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.

474 lines
13 KiB

  1. #include "perfmon.h"
  2. #include "status.h" // External declarations for this file
  3. #include <stdio.h> // for sprintf.
  4. #include <stdarg.h> // For ANSI variable args. Dont use UNIX <varargs.h>
  5. #include "log.h" // for LogCollecting
  6. #include "perfmops.h" // for SmallFileSizeString
  7. #include "playback.h" // for PlayingBackLog
  8. #include "utils.h"
  9. //================================//
  10. // Options for PaintStatusBar //
  11. //================================//
  12. #define PaintText 1
  13. #define PaintIcons 2
  14. #define PaintBoundary 4
  15. #define PaintAll (PaintText + PaintIcons + PaintBoundary)
  16. //==========================================================================//
  17. // Constants //
  18. //==========================================================================//
  19. #define szStatusClass TEXT("PerfmonStatusClass")
  20. #define dwStatusClassStyle (CS_HREDRAW | CS_VREDRAW | CS_OWNDC)
  21. #define iStatusClassExtra (0)
  22. #define iStatusWindowExtra (0)
  23. #define dwStatusWindowStyle (WS_CHILD | WS_VISIBLE)
  24. #define szAlertMax TEXT(" 99 ")
  25. #define szAlertFormat TEXT(" %2d ")
  26. #define szAlertOverflow TEXT(" ++")
  27. #define szLogMax TEXT(" 9,999.9M ")
  28. //==========================================================================//
  29. // Local Data //
  30. //==========================================================================//
  31. HDC hStatusDC ; // for OWN_DC
  32. HDC hLogBitmapDC ;
  33. int xLogBitmapWidth ;
  34. int yLogBitmapHeight ;
  35. HDC hAlertBitmapDC ;
  36. int xAlertBitmapWidth ;
  37. int yAlertBitmapHeight ;
  38. int yStatusHeight ;
  39. int xStatusAlertWidth ; // of alert bm and num alerts
  40. int xStatusLogWidth ; // of log bitmap and file size
  41. int szStatusLineLen ; // no. of char. in szStatusLine
  42. TCHAR szStatusLine [MessageLen+ResourceStringLen] ;
  43. TCHAR szCurrentActivity [ResourceStringLen] ;
  44. TCHAR szStatusFormat [ResourceStringLen] ;
  45. TCHAR szStatusFormat2 [ResourceStringLen] ;
  46. HBITMAP hBitmapAlertStatus ;
  47. HBITMAP hBitmapLogStatus ;
  48. //==========================================================================//
  49. // Macros //
  50. //==========================================================================//
  51. #define StatusTopMargin() (2)
  52. #define StatusLeftMargin() (2)
  53. //==========================================================================//
  54. // Local Functions //
  55. //==========================================================================//
  56. void
  57. DrawAlerts (
  58. HDC hDC,
  59. LPRECT lpRect
  60. )
  61. {
  62. TCHAR szText [10] ;
  63. RECT rectText ;
  64. int yBitmapTop ;
  65. if (!iUnviewedAlerts)
  66. return ;
  67. yBitmapTop = lpRect->top +
  68. (lpRect->bottom -
  69. lpRect->top -
  70. yAlertBitmapHeight) / 2 ;
  71. SetTextColor (hDC, crLastUnviewedAlert) ;
  72. BitBlt (hDC, // DC for Destination surface
  73. lpRect->right - xStatusAlertWidth, // x pos for Destination surface
  74. yBitmapTop, // y for Destination surface
  75. xAlertBitmapWidth, // width of bitmap
  76. yAlertBitmapHeight, // height of bitmap
  77. hAlertBitmapDC, // DC for source surface
  78. 0, 0, // location in source surface
  79. SRCCOPY) ; // ROP code
  80. SetTextColor (hDC, crBlack) ;
  81. if (iUnviewedAlerts > 99)
  82. lstrcpy (szText, szAlertOverflow) ;
  83. else
  84. TSPRINTF (szText, szAlertFormat, iUnviewedAlerts) ;
  85. rectText.left = lpRect->right - xStatusAlertWidth + xAlertBitmapWidth ;
  86. rectText.top = lpRect->top + 1 ;
  87. rectText.right = lpRect->right - 1 ;
  88. rectText.bottom = lpRect->bottom - 1 ;
  89. ExtTextOut (hDC, rectText.left, rectText.top, ETO_CLIPPED | ETO_OPAQUE,
  90. &rectText, szText, lstrlen (szText), NULL) ;
  91. lpRect->right -= (xStatusAlertWidth + (xAlertBitmapWidth >> 2)) ;
  92. }
  93. void
  94. DrawLog (
  95. HDC hDC,
  96. LPRECT lpRect
  97. )
  98. {
  99. TCHAR szText [10] ;
  100. RECT rectText ;
  101. int yBitmapTop ;
  102. if (!LogCollecting (hWndLog))
  103. return ;
  104. yBitmapTop = lpRect->top +
  105. (lpRect->bottom -
  106. lpRect->top -
  107. yLogBitmapHeight) / 2 ;
  108. BitBlt (hDC, // DC for Destination surface
  109. lpRect->right - xStatusLogWidth, // x pos for Destination surface
  110. yBitmapTop, // y for Destination surface
  111. xLogBitmapWidth, // width of bitmap
  112. yLogBitmapHeight, // height of bitmap
  113. hLogBitmapDC, // DC for source surface
  114. 0, 0, // location in source surface
  115. SRCCOPY) ; // ROP code
  116. SmallFileSizeString (LogFileSize (hWndLog), szText) ;
  117. rectText.left = lpRect->right - xStatusLogWidth +
  118. xLogBitmapWidth + 1 ;
  119. rectText.top = lpRect->top + 1 ;
  120. rectText.right = lpRect->right - 1 ;
  121. rectText.bottom = lpRect->bottom - 1 ;
  122. ExtTextOut (hDC, rectText.left, rectText.top, ETO_CLIPPED | ETO_OPAQUE,
  123. &rectText, szText, lstrlen (szText), NULL) ;
  124. lpRect->right -= xStatusLogWidth ;
  125. }
  126. //==========================================================================//
  127. // Message Handlers //
  128. //==========================================================================//
  129. void
  130. static
  131. OnCreate (
  132. HWND hWnd
  133. )
  134. /*
  135. Effect: Perform any actions needed when a status window is created.
  136. In particular, set the instance data to initial values,
  137. determine the size and placement of the various elements
  138. of the status display.
  139. Called By: StatusWndProc only, in response to a WM_CREATE message.
  140. */
  141. {
  142. HDC hDC ;
  143. hBitmapAlertStatus = LoadBitmap (hInstance, idBitmapAlertStatus) ;
  144. hBitmapLogStatus = LoadBitmap (hInstance, idBitmapLogStatus) ;
  145. hDC = hStatusDC = GetDC (hWnd) ;
  146. SelectFont (hDC, hFontScales) ;
  147. SetBkColor (hDC, ColorBtnFace) ;
  148. SetTextAlign (hDC, TA_LEFT) ;
  149. SetBkMode (hDC, OPAQUE) ;
  150. yStatusHeight = 2 * StatusTopMargin () +
  151. FontHeight (hDC, TRUE) +
  152. 2 * ThreeDPad ;
  153. BitmapDimemsion (hBitmapLogStatus, &yLogBitmapHeight, &xLogBitmapWidth) ;
  154. BitmapDimemsion (hBitmapAlertStatus, &yAlertBitmapHeight, &xAlertBitmapWidth) ;
  155. // pre-load the log and alert bitmaps for perfmormance
  156. hLogBitmapDC = CreateCompatibleDC (hDC) ;
  157. SelectObject (hLogBitmapDC, hBitmapLogStatus) ;
  158. hAlertBitmapDC = CreateCompatibleDC (hDC) ;
  159. SelectObject (hAlertBitmapDC, hBitmapAlertStatus) ;
  160. xStatusAlertWidth = xAlertBitmapWidth + 1 +
  161. TextWidth (hDC, szAlertMax) ;
  162. xStatusLogWidth = xLogBitmapWidth +
  163. TextWidth (hDC, szLogMax) ;
  164. StringLoad (IDS_CURRENTACTIVITY, szCurrentActivity) ;
  165. StringLoad (IDS_STATUSFORMAT, szStatusFormat) ;
  166. StringLoad (IDS_STATUSFORMAT2, szStatusFormat2) ;
  167. StatusLineReady (hWnd) ;
  168. }
  169. void
  170. static
  171. OnDestroy (
  172. HWND hWnd
  173. )
  174. {
  175. if (hBitmapAlertStatus) {
  176. DeleteObject (hBitmapAlertStatus) ;
  177. hBitmapAlertStatus = 0 ;
  178. }
  179. if (hBitmapLogStatus) {
  180. DeleteObject (hBitmapLogStatus) ;
  181. hBitmapLogStatus = 0 ;
  182. }
  183. ReleaseDC (hWnd, hStatusDC) ;
  184. }
  185. void
  186. static
  187. PaintStatusBar (
  188. HWND hWnd,
  189. HDC hDC,
  190. int PaintOptions
  191. )
  192. /*
  193. Effect: Paint the invalid surface of hWnd. Draw each label, each
  194. recessed value box, and each value.
  195. Called By: StatusWndProc only, in response to a WM_PAINT message.
  196. */
  197. {
  198. RECT rectClient ;
  199. if (bPerfmonIconic) {
  200. // no need to draw anything if iconic
  201. return ;
  202. }
  203. GetClientRect (hWnd, &rectClient) ;
  204. RectContract (&rectClient, StatusTopMargin (), StatusLeftMargin ()) ;
  205. if (PaintOptions == PaintAll) {
  206. ThreeDConcave1 (hDC,
  207. rectClient.left, rectClient.top,
  208. rectClient.right, rectClient.bottom) ;
  209. }
  210. rectClient.left += StatusLeftMargin () ;
  211. // Always draw the icons and need to draw log before Alerts!
  212. DrawLog (hDC, &rectClient) ;
  213. DrawAlerts (hDC, &rectClient) ;
  214. if (PaintOptions & PaintText) {
  215. rectClient.left += 1 ;
  216. rectClient.top += 1 ;
  217. rectClient.right -= 1 ;
  218. rectClient.bottom -= 1 ;
  219. ExtTextOut (hDC, rectClient.left, rectClient.top, ETO_CLIPPED | ETO_OPAQUE,
  220. &rectClient, szStatusLine, szStatusLineLen, NULL) ;
  221. }
  222. }
  223. LRESULT
  224. APIENTRY
  225. StatusWndProc (
  226. HWND hWnd,
  227. UINT wMsg,
  228. WPARAM wParam,
  229. LPARAM lParam
  230. )
  231. {
  232. BOOL bCallDefProc ;
  233. LRESULT lReturnValue ;
  234. HDC hDC ;
  235. PAINTSTRUCT ps ;
  236. bCallDefProc = FALSE ;
  237. lReturnValue = 0L ;
  238. switch (wMsg) {
  239. case WM_PAINT:
  240. hDC = BeginPaint (hWnd, &ps) ;
  241. PaintStatusBar (hWnd, hDC, PaintAll) ;
  242. EndPaint (hWnd, &ps) ;
  243. break ;
  244. case WM_CREATE:
  245. OnCreate (hWnd) ;
  246. break ;
  247. case WM_DESTROY:
  248. OnDestroy (hWnd) ;
  249. break ;
  250. default:
  251. bCallDefProc = TRUE ;
  252. }
  253. if (bCallDefProc)
  254. lReturnValue = DefWindowProc (hWnd, wMsg, wParam, lParam) ;
  255. return (lReturnValue);
  256. }
  257. int
  258. StatusHeight (
  259. HWND hWnd
  260. )
  261. /*
  262. Effect: A status window has a preferred height, based on the font
  263. used in its display. Return the preferred height, determined
  264. when the window was created.
  265. Assert: OnCreate has already been called, and it set
  266. StatusData.yHeight.
  267. */
  268. {
  269. return (yStatusHeight) ;
  270. }
  271. HWND
  272. CreatePMStatusWindow (
  273. HWND hWnd
  274. )
  275. {
  276. return (CreateWindow (szStatusClass, // class
  277. NULL, // caption
  278. dwStatusWindowStyle, // window style
  279. 0, 0, // position
  280. 0, 0, // size
  281. hWnd, // parent window
  282. NULL, // menu
  283. hInstance, // program instance
  284. NULL)) ; // user-supplied data
  285. }
  286. BOOL
  287. StatusInitializeApplication (void)
  288. /*
  289. Called By: InitializeApplication only
  290. */
  291. {
  292. WNDCLASS wc ;
  293. wc.style = dwStatusClassStyle ;
  294. wc.lpfnWndProc = StatusWndProc ;
  295. wc.hInstance = hInstance ;
  296. wc.cbClsExtra = iStatusClassExtra ;
  297. wc.cbWndExtra = iStatusWindowExtra ;
  298. wc.hIcon = NULL ;
  299. wc.hCursor = LoadCursor (NULL, IDC_ARROW) ;
  300. // wc.hbrBackground = hbLightGray ;
  301. wc.hbrBackground = hBrushFace ;
  302. wc.lpszMenuName = NULL ;
  303. wc.lpszClassName = szStatusClass ;
  304. return (RegisterClass (&wc)) ;
  305. }
  306. BOOL
  307. _cdecl
  308. StatusLine (
  309. HWND hWnd,
  310. WORD wStringID,
  311. ...
  312. )
  313. {
  314. TCHAR szFormat [MessageLen] ;
  315. va_list vaList ;
  316. if (wStringID == 0) {
  317. return (TRUE) ;
  318. }
  319. strclr (szStatusLine) ;
  320. if (LoadString (hInstance, wStringID, szFormat, MessageLen)) {
  321. va_start (vaList, wStringID) ;
  322. TSPRINTF (szStatusLine, szFormat, vaList) ;
  323. // wvsprintf (szStatusLine, szFormat, vaList) ;
  324. va_end (vaList) ;
  325. dwCurrentMenuID = MenuIDToHelpID (wStringID) ;
  326. szStatusLineLen = lstrlen (szStatusLine) ;
  327. } else {
  328. dwCurrentMenuID = 0 ;
  329. szStatusLineLen = 0 ;
  330. }
  331. PaintStatusBar (hWndStatus, hStatusDC, PaintText + PaintIcons) ;
  332. return (TRUE) ;
  333. }
  334. void
  335. StatusLineReady (
  336. HWND hWnd
  337. )
  338. {
  339. int stringLen ;
  340. LPTSTR pFileName = NULL ;
  341. TSPRINTF (szStatusLine, szStatusFormat,
  342. PlayingBackLog () ?
  343. PlaybackLog.szFileTitle : szCurrentActivity) ;
  344. switch (iPerfmonView) {
  345. case IDM_VIEWCHART:
  346. pFileName = pChartFileName ;
  347. break ;
  348. case IDM_VIEWALERT:
  349. pFileName = pAlertFileName ;
  350. break ;
  351. case IDM_VIEWLOG:
  352. pFileName = pLogFileName ;
  353. break ;
  354. case IDM_VIEWREPORT:
  355. pFileName = pReportFileName ;
  356. break ;
  357. }
  358. if (pFileName) {
  359. stringLen = lstrlen (szStatusLine) ;
  360. TSPRINTF (&szStatusLine[stringLen], szStatusFormat2, pFileName) ;
  361. }
  362. szStatusLineLen = lstrlen (szStatusLine) ;
  363. PaintStatusBar (hWndStatus, hStatusDC, PaintText + PaintIcons) ;
  364. }
  365. void
  366. StatusUpdateIcons (
  367. HWND hWndStatus
  368. )
  369. {
  370. PaintStatusBar (hWndStatus, hStatusDC, PaintIcons) ;
  371. }