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.

342 lines
9.0 KiB

  1. //
  2. //
  3. //
  4. #include "stdafx.h"
  5. #include "ProcessOpt.h"
  6. class CTimePickerDlg :
  7. public CDialogImpl<CTimePickerDlg>,
  8. public WTL::CWinDataExchange<CTimePickerDlg>
  9. {
  10. public:
  11. CTimePickerDlg()
  12. {
  13. m_TopLeft.x = m_TopLeft.y = 0;
  14. ZeroMemory(&m_tm, sizeof(SYSTEMTIME));
  15. }
  16. ~CTimePickerDlg()
  17. {
  18. }
  19. enum {IDD = IDD_TIME_PICKER};
  20. BEGIN_MSG_MAP_EX(CTimePickerDlg)
  21. MSG_WM_INITDIALOG(OnInitDialog)
  22. COMMAND_HANDLER_EX(IDOK, BN_CLICKED, OnButton)
  23. COMMAND_HANDLER_EX(IDCANCEL, BN_CLICKED, OnButton)
  24. END_MSG_MAP()
  25. BEGIN_DDX_MAP(CTimePickerDlg)
  26. DDX_CONTROL(IDC_TIME_PICKER, m_Timer)
  27. END_DDX_MAP()
  28. LRESULT OnInitDialog(HWND hDlg, LPARAM lParam);
  29. void OnButton(UINT nCode, UINT nID, HWND hWnd);
  30. CTimePickerExch m_Timer;
  31. SYSTEMTIME m_tm;
  32. POINT m_TopLeft;
  33. };
  34. LRESULT
  35. CTimePickerDlg::OnInitDialog(HWND hDlg, LPARAM lParam)
  36. {
  37. DoDataExchange();
  38. m_Timer.SetFormat(_T("HH:mm"));
  39. m_Timer.SetSystemTime(GDT_VALID, &m_tm);
  40. ::SetWindowPos(m_hWnd, NULL,
  41. m_TopLeft.x, m_TopLeft.y, 0, 0,
  42. SWP_NOSIZE | SWP_NOZORDER);
  43. return FALSE;
  44. }
  45. void
  46. CTimePickerDlg::OnButton(UINT nCode, UINT nID, HWND hWnd)
  47. {
  48. if (nID == IDOK)
  49. m_Timer.GetSystemTime(&m_tm);
  50. EndDialog(nID);
  51. }
  52. LRESULT
  53. CProcessOptPage::OnInitDialog(HWND hDlg, LPARAM lParam)
  54. {
  55. DoDataExchange();
  56. UDACCEL toAcc[3] = {{1, 1}, {3, 5}, {6, 10}};
  57. m_TimeoutSpin.SetRange32(TIMEOUT_MIN, TIMEOUT_MAX);
  58. m_TimeoutSpin.SetPos32(m_pData->m_CgiTimeout);
  59. m_TimeoutSpin.SetAccel(3, toAcc);
  60. m_TimespanSpin.SetRange32(TIMESPAN_MIN, TIMESPAN_MAX);
  61. m_TimespanSpin.SetPos32(m_pData->m_Timespan);
  62. m_TimespanSpin.SetAccel(3, toAcc);
  63. m_RequestSpin.SetRange32(REQUESTS_MIN, REQUESTS_MAX);
  64. m_RequestSpin.SetPos32(m_pData->m_Requests);
  65. m_RequestSpin.SetAccel(3, toAcc);
  66. m_TimespanCtrl.EnableWindow(m_pData->m_RecycleTimespan);
  67. m_TimespanSpin.EnableWindow(m_pData->m_RecycleTimespan);
  68. m_RequestCtrl.EnableWindow(m_pData->m_RecycleRequest);
  69. m_RequestSpin.EnableWindow(m_pData->m_RecycleRequest);
  70. m_TimerList.EnableWindow(m_pData->m_RecycleTimer);
  71. m_AddTimer.EnableWindow(m_pData->m_RecycleTimer);
  72. int count = m_pData->m_Timers.size();
  73. if (count > 0)
  74. {
  75. CStringListEx::iterator it;
  76. int idx;
  77. for (idx = 0, it = m_pData->m_Timers.begin(); it != m_pData->m_Timers.end(); it++, idx++)
  78. {
  79. int pos = (*it).find(_T(':'));
  80. int len = (*it).GetLength();
  81. WORD h = (WORD)StrToInt((*it).Left(pos));
  82. WORD m = (WORD)StrToInt((*it).Right(len - pos - 1));
  83. m_TimerList.AddString((LPCTSTR)UIntToPtr(MAKELONG(m, h)));
  84. }
  85. m_TimerList.SetCurSel(0);
  86. }
  87. m_ChangeTimer.EnableWindow(count > 0);
  88. m_DeleteTimer.EnableWindow(count > 0);
  89. DoDataExchange(TRUE);
  90. return FALSE;
  91. }
  92. LRESULT
  93. CProcessOptPage::OnCompareItem(UINT nID, LPCOMPAREITEMSTRUCT cmpi)
  94. {
  95. if (nID == IDC_TIMES_LIST)
  96. {
  97. ASSERT(cmpi->CtlType == ODT_LISTBOX);
  98. if (cmpi->itemData1 > cmpi->itemData2)
  99. return 1;
  100. else if (cmpi->itemData1 == cmpi->itemData2)
  101. return 0;
  102. else
  103. return -1;
  104. }
  105. ASSERT(FALSE);
  106. return 0;
  107. }
  108. LRESULT
  109. CProcessOptPage::OnMeasureItem(UINT nID, LPMEASUREITEMSTRUCT mi)
  110. {
  111. if (nID == IDC_TIMES_LIST)
  112. {
  113. HWND hwnd = GetDlgItem(IDC_TIMES_LIST);
  114. HDC hdc = ::GetDC(hwnd);
  115. HFONT hFont = (HFONT)SendDlgItemMessage(IDC_TIMES_LIST, WM_GETFONT, 0, 0);
  116. HFONT hf = (HFONT)::SelectObject(hdc, hFont);
  117. TEXTMETRIC tm;
  118. ::GetTextMetrics(hdc, &tm);
  119. ::SelectObject(hdc, hf);
  120. ::ReleaseDC(hwnd, hdc);
  121. RECT rc;
  122. ::GetClientRect(hwnd, &rc);
  123. mi->itemHeight = tm.tmHeight;
  124. mi->itemWidth = rc.right - rc.left;
  125. }
  126. return TRUE;
  127. }
  128. LRESULT
  129. CProcessOptPage::OnDrawItem(UINT nID, LPDRAWITEMSTRUCT di)
  130. {
  131. if (nID == IDC_TIMES_LIST && di->itemID != -1)
  132. {
  133. SYSTEMTIME tm;
  134. ::GetSystemTime(&tm);
  135. tm.wMinute = LOWORD(di->itemData);
  136. tm.wHour = HIWORD(di->itemData);
  137. TCHAR buf[32];
  138. TCHAR fmt[] = _T("HH:mm");
  139. ::GetTimeFormat(NULL /*LOCALE_SYSTEM_DEFAULT*/, TIME_NOSECONDS, &tm, fmt, buf, 32);
  140. HBRUSH hBrush;
  141. COLORREF prevText;
  142. COLORREF prevBk;
  143. switch (di->itemAction)
  144. {
  145. case ODA_SELECT:
  146. case ODA_DRAWENTIRE:
  147. if (di->itemState & ODS_SELECTED)
  148. {
  149. hBrush = ::CreateSolidBrush(GetSysColor(COLOR_HIGHLIGHT));
  150. prevText = ::SetTextColor(di->hDC, GetSysColor(COLOR_HIGHLIGHTTEXT));
  151. prevBk = ::SetBkColor(di->hDC, GetSysColor(COLOR_HIGHLIGHT));
  152. }
  153. else
  154. {
  155. hBrush = CreateSolidBrush(GetSysColor(COLOR_WINDOW));
  156. prevText = ::SetTextColor(di->hDC, GetSysColor(COLOR_WINDOWTEXT));
  157. prevBk = ::SetBkColor(di->hDC, GetSysColor(COLOR_WINDOW));
  158. }
  159. ::FillRect(di->hDC, &di->rcItem, hBrush);
  160. ::DrawText(di->hDC, buf, -1, &di->rcItem, DT_LEFT | DT_VCENTER | DT_EXTERNALLEADING);
  161. ::SetTextColor(di->hDC, prevText);
  162. ::SetTextColor(di->hDC, prevBk);
  163. ::DeleteObject(hBrush);
  164. break;
  165. case ODA_FOCUS:
  166. break;
  167. }
  168. }
  169. return TRUE;
  170. }
  171. void
  172. CProcessOptPage::OnRecycleTimespan(UINT nCode, UINT nID, HWND hWnd)
  173. {
  174. DoDataExchange(TRUE, IDC_RECYCLE_TIMESPAN);
  175. m_TimespanCtrl.EnableWindow(m_pData->m_RecycleTimespan);
  176. m_TimespanSpin.EnableWindow(m_pData->m_RecycleTimespan);
  177. SET_MODIFIED(TRUE);
  178. }
  179. void
  180. CProcessOptPage::OnRecycleRequest(UINT nCode, UINT nID, HWND hWnd)
  181. {
  182. DoDataExchange(TRUE, IDC_RECYCLE_REQUESTS);
  183. m_RequestCtrl.EnableWindow(m_pData->m_RecycleRequest);
  184. m_RequestSpin.EnableWindow(m_pData->m_RecycleRequest);
  185. SET_MODIFIED(TRUE);
  186. }
  187. void
  188. CProcessOptPage::OnRecycleTimer(UINT nCode, UINT nID, HWND hWnd)
  189. {
  190. DoDataExchange(TRUE, IDC_RECYCLE_TIMER);
  191. m_TimerList.EnableWindow(m_pData->m_RecycleTimer);
  192. m_AddTimer.EnableWindow(m_pData->m_RecycleTimer);
  193. SET_MODIFIED(TRUE);
  194. }
  195. void
  196. CProcessOptPage::OnTimeSelChanged(UINT nCode, UINT nID, HWND hWnd)
  197. {
  198. int idx = m_TimerList.GetCurSel();
  199. m_ChangeTimer.EnableWindow(idx != LB_ERR);
  200. m_DeleteTimer.EnableWindow(idx != LB_ERR);
  201. }
  202. void
  203. CProcessOptPage::OnAddTimer(UINT nCode, UINT nID, HWND hWnd)
  204. {
  205. CTimePickerDlg dlg;
  206. RECT rc;
  207. m_AddTimer.GetWindowRect(&rc);
  208. dlg.m_TopLeft.x = rc.left;
  209. dlg.m_TopLeft.y = rc.bottom;
  210. if (dlg.DoModal(m_hWnd) == IDOK)
  211. {
  212. int idx;
  213. LONG_PTR l = (LONG_PTR)MAKELONG(dlg.m_tm.wMinute, dlg.m_tm.wHour);
  214. if ((idx = m_TimerList.FindString(-1,
  215. (LPCTSTR)l)) == LB_ERR)
  216. {
  217. idx = m_TimerList.AddString((LPCTSTR)l);
  218. m_TimerList.SetCurSel(idx);
  219. m_ChangeTimer.EnableWindow(idx != LB_ERR);
  220. m_DeleteTimer.EnableWindow(idx != LB_ERR);
  221. }
  222. else
  223. m_TimerList.SetCurSel(idx);
  224. SET_MODIFIED(TRUE);
  225. }
  226. }
  227. void
  228. CProcessOptPage::OnChangeTimer(UINT, UINT, HWND)
  229. {
  230. CTimePickerDlg dlg;
  231. RECT rc;
  232. m_ChangeTimer.GetWindowRect(&rc);
  233. dlg.m_TopLeft.x = rc.left;
  234. dlg.m_TopLeft.y = rc.bottom;
  235. int idx = m_TimerList.GetCurSel();
  236. LONG l = (LONG)m_TimerList.GetItemData(idx);
  237. // Looks like we have to init the struct properly
  238. ::GetSystemTime(&dlg.m_tm);
  239. dlg.m_tm.wMinute = LOWORD(l);
  240. dlg.m_tm.wHour = HIWORD(l);
  241. dlg.m_tm.wSecond = 0;
  242. if (dlg.DoModal(m_hWnd) == IDOK)
  243. {
  244. RECT rc;
  245. m_TimerList.SetItemData(idx,
  246. (DWORD_PTR)MAKELONG(dlg.m_tm.wMinute, dlg.m_tm.wHour));
  247. m_TimerList.GetItemRect(idx, &rc);
  248. ::InvalidateRect(GetDlgItem(IDC_TIMES_LIST), &rc, TRUE);
  249. SET_MODIFIED(TRUE);
  250. }
  251. }
  252. void
  253. CProcessOptPage::OnDeleteTimer(UINT nCode, UINT nID, HWND hWnd)
  254. {
  255. int idx = m_TimerList.GetCurSel();
  256. int count;
  257. if (idx != LB_ERR)
  258. {
  259. m_TimerList.DeleteString(idx);
  260. SET_MODIFIED(TRUE);
  261. if ((count = m_TimerList.GetCount()) == 0)
  262. {
  263. m_DeleteTimer.EnableWindow(FALSE);
  264. m_ChangeTimer.EnableWindow(FALSE);
  265. }
  266. else
  267. {
  268. m_TimerList.SetCurSel(idx == count ? --idx : idx);
  269. }
  270. }
  271. }
  272. BOOL
  273. CProcessOptPage::OnKillActive()
  274. {
  275. BOOL bRes = FALSE;
  276. do
  277. {
  278. DoDataExchange(TRUE, IDC_LOG_FAILS);
  279. DoDataExchange(TRUE, IDC_DEBUG_EXCEPTION);
  280. DoDataExchange(TRUE, IDC_CGI_TIMEOUT);
  281. DoDataExchange(TRUE, IDC_RECYCLE_TIMESPAN);
  282. if (m_pData->m_RecycleTimespan && !DoDataExchange(TRUE, IDC_TIMESPAN))
  283. {
  284. break;
  285. }
  286. DoDataExchange(TRUE, IDC_RECYCLE_REQUESTS);
  287. if (m_pData->m_RecycleRequest && !DoDataExchange(TRUE, IDC_REQUEST_LIMIT))
  288. {
  289. break;
  290. }
  291. int count = m_TimerList.GetCount();
  292. TCHAR buf[32];
  293. SYSTEMTIME tm;
  294. ::GetSystemTime(&tm);
  295. m_pData->m_Timers.Clear();
  296. for (int i = 0; i < count; i++)
  297. {
  298. DWORD data = (DWORD)m_TimerList.GetItemData(i);
  299. tm.wMinute = LOWORD(data);
  300. tm.wHour = HIWORD(data);
  301. ::GetTimeFormat(LOCALE_SYSTEM_DEFAULT,
  302. TIME_NOSECONDS | TIME_FORCE24HOURFORMAT,
  303. &tm, _T("hh':'mm"), buf, 32);
  304. m_pData->m_Timers.PushBack(buf);
  305. }
  306. bRes = TRUE;
  307. } while (FALSE);
  308. return bRes;
  309. }