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.

331 lines
9.0 KiB

  1. //==========================================================================//
  2. // Includes //
  3. //==========================================================================//
  4. #include <stdio.h>
  5. #include "perfmon.h" // included by all source
  6. #include "timefrm.h" // external declarations for this file
  7. #include "alert.h" // for PlaybackAlert
  8. #include "grafdata.h" // for PlaybackChart
  9. #include "perfmops.h" // for PerfmonViewWindow
  10. #include "playback.h" // for PlaybackIndexN
  11. #include "report.h" // for PlaybackReport
  12. #include "timeline.h" // for TL_INTERVAL
  13. #include "utils.h"
  14. #include "pmhelpid.h" // for Help IDs
  15. //==========================================================================//
  16. // Local Data //
  17. //==========================================================================//
  18. static RECT TFrameRectWindow ;
  19. //==========================================================================//
  20. // Local Functions //
  21. //==========================================================================//
  22. void
  23. ClearSystemTime (
  24. SYSTEMTIME *pSystemTime
  25. )
  26. {
  27. pSystemTime->wYear = 0 ;
  28. pSystemTime->wMonth = 0 ;
  29. pSystemTime->wDayOfWeek = 0 ;
  30. pSystemTime->wDay = 0 ;
  31. pSystemTime->wHour = 0 ;
  32. pSystemTime->wMinute = 0 ;
  33. pSystemTime->wSecond = 0 ;
  34. pSystemTime->wMilliseconds = 0 ;
  35. }
  36. //==========================================================================//
  37. // Message Handlers //
  38. //==========================================================================//
  39. void
  40. static
  41. OnInitDialog (
  42. HDLG hDlg
  43. )
  44. {
  45. PBOOKMARK pBookmark ;
  46. int iIndex ;
  47. TCHAR szText [20+20+BookmarkCommentLen] ;
  48. TCHAR szDate [20] ;
  49. TCHAR szTime [20] ;
  50. int iBookmarksNum ;
  51. HWND hWndTLine ;
  52. HWND hWndBookmarks ;
  53. int currentTextExtent = 0 ;
  54. int maxTextExtent = 0 ;
  55. HDC hDC = 0 ;
  56. HFONT hFont ;
  57. hWndTLine = DialogControl (hDlg, IDD_TIMEFRAMETIMELINE) ;
  58. hWndBookmarks = DialogControl (hDlg, IDD_TIMEFRAMEBOOKMARKS) ;
  59. SetFont (hWndBookmarks, hFontScales) ;
  60. LBSetHorzExtent (hWndBookmarks, 0) ;
  61. TLineSetRange (hWndTLine, 0, PlaybackLog.iTotalTics - 1) ;
  62. TLineSetStart (hWndTLine, PlaybackLog.StartIndexPos.iPosition) ;
  63. TLineSetStop (hWndTLine, PlaybackLog.StopIndexPos.iPosition) ;
  64. iBookmarksNum = 0 ;
  65. pBookmark = PlaybackLog.pBookmarkFirst ;
  66. if (pBookmark) {
  67. hDC = GetDC (hWndBookmarks) ;
  68. if (hDC) {
  69. hFont = (HFONT)SendMessage(hWndBookmarks, WM_GETFONT, 0, 0L);
  70. if (hFont)
  71. SelectObject(hDC, hFont);
  72. }
  73. while (pBookmark) {
  74. SystemTimeDateString (&(pBookmark->SystemTime), szDate) ;
  75. SystemTimeTimeString (&(pBookmark->SystemTime), szTime, TRUE) ;
  76. TSPRINTF (szText, TEXT(" %s %s %s"),
  77. szDate, szTime,
  78. pBookmark->szComment) ;
  79. LBSetData (hWndBookmarks, LBAdd (hWndBookmarks, szText), pBookmark->iTic) ;
  80. // get the biggest text width
  81. if (hDC) {
  82. currentTextExtent = TextWidth (hDC, szText) + xScrollWidth / 2 ;
  83. if (currentTextExtent > maxTextExtent) {
  84. maxTextExtent = currentTextExtent ;
  85. }
  86. }
  87. pBookmark = pBookmark->pBookmarkNext ;
  88. }
  89. LBSetSelection (hWndBookmarks, 0) ;
  90. iBookmarksNum = LBNumItems (hWndBookmarks) ;
  91. }
  92. if (iBookmarksNum == 0) {
  93. DialogEnable (hDlg, IDD_TIMEFRAMEBOOKMARKS, FALSE) ;
  94. DialogEnable (hDlg, IDD_TIMEFRAMEBOOKMARKGRP, FALSE) ;
  95. DialogEnable (hDlg, IDD_TIMEFRAMESETSTART, FALSE) ;
  96. DialogEnable (hDlg, IDD_TIMEFRAMESETSTOP, FALSE) ;
  97. } else {
  98. LBSetHorzExtent (hWndBookmarks, maxTextExtent) ;
  99. }
  100. if (hDC) {
  101. ReleaseDC (hWndBookmarks, hDC) ;
  102. }
  103. if (TFrameRectWindow.right == TFrameRectWindow.left) {
  104. // we have not initialize this data yet.
  105. // will get init. after the first time frame window invoke
  106. WindowCenter (hDlg) ;
  107. } else {
  108. // show it in its previous position
  109. MoveWindow (hDlg,
  110. TFrameRectWindow.left,
  111. TFrameRectWindow.top,
  112. TFrameRectWindow.right - TFrameRectWindow.left,
  113. TFrameRectWindow.bottom - TFrameRectWindow.top,
  114. TRUE) ;
  115. }
  116. dwCurrentDlgID = HC_PM_idDlgEditTimeFrame ;
  117. }
  118. void
  119. static
  120. OnTLineInterval (
  121. HDLG hDlg,
  122. int iInterval,
  123. SYSTEMTIME *pSystemTime
  124. )
  125. {
  126. PLOGINDEX pIndex ;
  127. pIndex = PlaybackIndexN (iInterval) ;
  128. if (pIndex)
  129. *pSystemTime = pIndex->SystemTime ;
  130. else
  131. ClearSystemTime (pSystemTime) ;
  132. }
  133. void
  134. static
  135. OnOK (
  136. HDLG hDlg
  137. )
  138. {
  139. LOGPOSITION lp ;
  140. int iIndex ;
  141. HWND hWndTLine = DialogControl (hDlg, IDD_TIMEFRAMETIMELINE) ;
  142. iIndex = TLineStart (hWndTLine) ;
  143. if (LogPositionN (iIndex, &lp))
  144. PlaybackLog.StartIndexPos = lp ;
  145. iIndex = TLineStop (hWndTLine) ;
  146. if (LogPositionN (iIndex, &lp))
  147. PlaybackLog.StopIndexPos = lp ;
  148. PlaybackLog.iSelectedTics =
  149. PlaybackLog.StopIndexPos.iPosition -
  150. PlaybackLog.StartIndexPos.iPosition + 1 ;
  151. PlaybackChart (hWndGraph) ;
  152. PlaybackAlert (hWndAlert, 0) ;
  153. PlaybackReport (hWndReport) ;
  154. WindowInvalidate (PerfmonViewWindow ()) ;
  155. GetWindowRect (hDlg, &TFrameRectWindow) ;
  156. dwCurrentDlgID = 0 ;
  157. }
  158. void
  159. static
  160. OnCancel (
  161. HWND hWnd
  162. )
  163. {
  164. HDC hGraphDC ;
  165. PGRAPHSTRUCT pGraph ;
  166. hGraphDC = GetDC (hWndGraph) ;
  167. if (!hGraphDC)
  168. return;
  169. pGraph = GraphData (hWndGraph) ;
  170. if (!pGraph) {
  171. ReleaseDC(hWndGraph, hGraphDC);
  172. return ;
  173. }
  174. TLineRedraw (hGraphDC, pGraph) ;
  175. GetWindowRect (hWnd, &TFrameRectWindow) ;
  176. dwCurrentDlgID = 0 ;
  177. }
  178. void
  179. OnSetStartStop (
  180. HWND hDlg,
  181. BOOL bSetStart
  182. )
  183. {
  184. int iTic ;
  185. int iStopTic ;
  186. int iStartTic ;
  187. HWND hWndTLine = DialogControl (hDlg, IDD_TIMEFRAMETIMELINE) ;
  188. HWND hWndBookmarks = DialogControl (hDlg, IDD_TIMEFRAMEBOOKMARKS) ;
  189. iStartTic = TLineStart (hWndTLine) ;
  190. iStopTic = TLineStop (hWndTLine) ;
  191. iTic = (int)LBData (hWndBookmarks, LBSelection (hWndBookmarks)) ;
  192. if ((bSetStart && iStopTic <= iTic) ||
  193. (!bSetStart && iStartTic >= iTic)) {
  194. DlgErrorBox (hDlg, ERR_STOPBEFORESTART) ;
  195. } else {
  196. if (bSetStart) {
  197. TLineSetStart (hWndTLine, iTic) ;
  198. } else {
  199. TLineSetStop (hWndTLine, iTic) ;
  200. }
  201. WindowInvalidate (hWndTLine) ;
  202. }
  203. }
  204. //==========================================================================//
  205. // Exported Functions //
  206. //==========================================================================//
  207. INT_PTR
  208. TimeframeDlgProc (
  209. HWND hDlg,
  210. UINT iMessage,
  211. WPARAM wParam,
  212. LPARAM lParam
  213. )
  214. {
  215. BOOL bHandled ;
  216. bHandled = TRUE ;
  217. switch (iMessage) {
  218. case TL_INTERVAL:
  219. OnTLineInterval (hDlg, (int)wParam, (SYSTEMTIME *) lParam) ;
  220. break ;
  221. case WM_INITDIALOG:
  222. OnInitDialog (hDlg) ;
  223. return (TRUE) ;
  224. case WM_CLOSE:
  225. OnCancel (hDlg) ;
  226. EndDialog (hDlg, 0) ;
  227. break ;
  228. case WM_COMMAND:
  229. switch (wParam) {
  230. case IDD_OK:
  231. SetHourglassCursor() ;
  232. OnOK (hDlg) ;
  233. SetArrowCursor() ;
  234. EndDialog (hDlg, 1) ;
  235. break ;
  236. case IDD_TIMEFRAMESETSTART:
  237. case IDD_TIMEFRAMESETSTOP:
  238. OnSetStartStop (hDlg, wParam == IDD_TIMEFRAMESETSTART) ;
  239. break ;
  240. case IDD_CANCEL:
  241. OnCancel (hDlg) ;
  242. GetWindowRect (hDlg, &TFrameRectWindow) ;
  243. EndDialog (hDlg, 0) ;
  244. break ;
  245. case IDD_TIMEFRAMEHELP:
  246. CallWinHelp (dwCurrentDlgID, hDlg) ;
  247. break ;
  248. default:
  249. bHandled = FALSE ;
  250. break;
  251. }
  252. break;
  253. default:
  254. bHandled = FALSE ;
  255. break ;
  256. }
  257. return (bHandled) ;
  258. }
  259. BOOL
  260. SetTimeframe (
  261. HWND hWndParent
  262. )
  263. {
  264. if (DialogBox (hInstance, idDlgTimeframe, hWndParent, TimeframeDlgProc)) {
  265. return (TRUE) ;
  266. }
  267. return (FALSE) ;
  268. }