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.

349 lines
10 KiB

  1. /*****************************************************************************
  2. *
  3. * Graph.c - This module handles the graphing window.
  4. *
  5. * Microsoft Confidential
  6. * Copyright (c) 1992-1993 Microsoft Corporation
  7. *
  8. *
  9. ****************************************************************************/
  10. /*
  11. File Contents:
  12. This file contains the code for creating and manipulating the graph
  13. window. This window is a child of hWndMain and represents one of the
  14. three "views" of the program. The other views are log and alert.
  15. The graph window is actually just a container window, whose surface
  16. is completely filled by its children: hWndGraphDisplay, ,
  17. hWndGraphLegend, and hWndGraphStatus. Therefore much of this file is
  18. merely calls to the appropriate functions for these children.
  19. The graph window is responsible for the graph structure itself,
  20. however. Conceptually this should be instance data for the graph
  21. window. Right now, however, there is only one window and only one
  22. graph structure. Nevertheless, we go through the GraphData(hWnd)
  23. function to get a pointer to the graph structure for the graph window.
  24. */
  25. //==========================================================================//
  26. // Includes //
  27. //==========================================================================//
  28. #include "perfmon.h"
  29. #include "graph.h"
  30. #include "grafdisp.h"
  31. #include "legend.h"
  32. #include "valuebar.h"
  33. #include "utils.h" // for WindowShow
  34. //==========================================================================//
  35. // Constants //
  36. //==========================================================================//
  37. //=============================//
  38. // Graph Class //
  39. //=============================//
  40. TCHAR szGraphWindowClass[] = TEXT("PerfGraph") ;
  41. #define dwGraphClassStyle (CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS)
  42. #define iGraphClassExtra (0)
  43. #define iGraphWindowExtra (0)
  44. #define dwGraphWindowStyle (WS_CHILD)
  45. //==========================================================================//
  46. // Local Functions //
  47. //==========================================================================//
  48. void
  49. static
  50. OnCreate (
  51. HWND hWnd
  52. )
  53. {
  54. hWndGraphDisplay = CreateGraphDisplayWindow (hWnd) ;
  55. hWndGraphLegend = CreateGraphLegendWindow (hWnd) ;
  56. hWndGraphStatus = CreateGraphStatusWindow (hWnd) ;
  57. }
  58. void
  59. static
  60. OnPaint (
  61. HWND hWnd
  62. )
  63. {
  64. HDC hDC ;
  65. PAINTSTRUCT ps ;
  66. hDC = BeginPaint (hWnd, &ps) ;
  67. EndPaint (hWnd, &ps) ;
  68. }
  69. void
  70. static
  71. OnSize (
  72. HWND hWnd,
  73. int xWidth,
  74. int yHeight
  75. )
  76. {
  77. SizeGraphComponents (hWnd) ;
  78. }
  79. //==========================================================================//
  80. // Message Handlers //
  81. //==========================================================================//
  82. LRESULT
  83. APIENTRY
  84. GraphWndProc (
  85. HWND hWnd,
  86. UINT wMsg,
  87. WPARAM wParam,
  88. LPARAM lParam
  89. )
  90. {
  91. BOOL bCallDefProc ;
  92. LRESULT lReturnValue ;
  93. bCallDefProc = FALSE ;
  94. lReturnValue = 0L ;
  95. switch (wMsg) {
  96. case WM_CREATE:
  97. OnCreate (hWnd) ;
  98. break ;
  99. case WM_LBUTTONDBLCLK:
  100. SendMessage (hWndMain, WM_LBUTTONDBLCLK, wParam, lParam) ;
  101. break ;
  102. case WM_PAINT:
  103. OnPaint (hWnd) ;
  104. break ;
  105. case WM_SIZE:
  106. OnSize (hWnd, LOWORD (lParam), HIWORD (lParam)) ;
  107. break ;
  108. default:
  109. bCallDefProc = TRUE ;
  110. }
  111. if (bCallDefProc)
  112. lReturnValue = DefWindowProc (hWnd, wMsg, wParam, lParam) ;
  113. return (lReturnValue);
  114. }
  115. BOOL
  116. GraphInitializeApplication (void)
  117. /*
  118. Note: There is no background brush set for the MainWindow
  119. class so that the main window is never erased. The
  120. client area of MainWindow is always covered by one
  121. of the view windows. If we erase it, it would just
  122. flicker needlessly.
  123. */
  124. {
  125. BOOL bSuccess ;
  126. WNDCLASS wc ;
  127. //=============================//
  128. // Register GraphWindow class //
  129. //=============================//
  130. wc.style = dwGraphClassStyle ;
  131. wc.lpfnWndProc = GraphWndProc ;
  132. wc.hInstance = hInstance ;
  133. wc.cbClsExtra = iGraphWindowExtra ;
  134. wc.cbWndExtra = iGraphClassExtra ;
  135. wc.hIcon = NULL ;
  136. wc.hCursor = LoadCursor(NULL, IDC_ARROW) ;
  137. wc.hbrBackground = NULL ; // see note above
  138. wc.lpszMenuName = NULL ;
  139. wc.lpszClassName = szGraphWindowClass ;
  140. bSuccess = RegisterClass (&wc) ;
  141. //=============================//
  142. // Register Child classes //
  143. //=============================//
  144. if (bSuccess)
  145. bSuccess = GraphDisplayInitializeApplication () ;
  146. if (bSuccess)
  147. bSuccess = GraphLegendInitializeApplication () ;
  148. if (bSuccess)
  149. bSuccess = GraphStatusInitializeApplication () ;
  150. return (bSuccess) ;
  151. }
  152. HWND
  153. CreateGraphWindow (
  154. HWND hWndParent
  155. )
  156. /*
  157. Effect: Create the graph window. This window is a child of
  158. hWndMain and is a container for the graph data,
  159. graph label, graph legend, and graph status windows.
  160. Note: We dont worry about the size here, as this window
  161. will be resized whenever the main window is resized.
  162. */
  163. {
  164. return (CreateWindow (szGraphWindowClass, // window class
  165. NULL, // caption
  166. dwGraphWindowStyle, // style for window
  167. 0, 0, // initial position
  168. 0, 0, // initial size
  169. hWndParent, // parent
  170. NULL, // menu
  171. hInstance, // program instance
  172. NULL)) ; // user-supplied data
  173. }
  174. void
  175. SizeGraphComponents (
  176. HWND hWnd
  177. )
  178. /*
  179. Effect: Move and show the various components of the graph to
  180. fill the size (xWidth x yHeight). Take into account
  181. whether the user wants to show the legend or status
  182. bars. Also take into account if we have room for these
  183. items.
  184. Internals: If the user doesn't want the status or legend windows,
  185. they aren't shown. Also, if the user wanted the status
  186. window but not the legend window, the status window is
  187. not shown.
  188. We may disregard the user's desire for the legend or
  189. status bar if there is not room. In particular, a legend
  190. window has a minimum width (LegendMinWidth ()) and a
  191. minimum height (LegendMinHeight ()). These values are
  192. fixed for a given session of perfmon. It also has a
  193. preferred height, which takes into consideration the
  194. size of the graph window and the number of items in
  195. the legend. This value is returned by LegendHeight().
  196. We don't show the legend if its minimum height would
  197. take up more than half the graph height.
  198. If we feel we don't have room for the legend, we don't
  199. show the status window either.
  200. See Also: LegendMinWidth, LegendMinHeight, LegendHeight,
  201. ValuebarHeight.
  202. Called By: OnSize, any other function that may remove or add one
  203. of the graph components.
  204. */
  205. {
  206. RECT rectClient ;
  207. BOOL bShowLegend ;
  208. BOOL bShowStatus ;
  209. int yStatusHeight ;
  210. int yLegendHeight ;
  211. int xWidth ;
  212. int yHeight ;
  213. GetClientRect (hWnd, &rectClient) ;
  214. xWidth = rectClient.right - rectClient.left ;
  215. yHeight = rectClient.bottom - rectClient.top ;
  216. // if the graph window has no size, neither will its children.
  217. if (!xWidth || !yHeight)
  218. return ;
  219. //=============================//
  220. // Show the Legend Window? //
  221. //=============================//
  222. if (!pGraphs->gOptions.bLegendChecked)
  223. bShowLegend = FALSE ;
  224. else if (xWidth < LegendMinWidth (hWndGraphLegend))
  225. bShowLegend = FALSE ;
  226. else if (yHeight < 5 * LegendMinHeight (hWndGraphLegend))
  227. bShowLegend = FALSE ;
  228. else
  229. bShowLegend = TRUE ;
  230. //=============================//
  231. // Show the Status Window? //
  232. //=============================//
  233. if (!pGraphs->gOptions.bStatusBarChecked)
  234. bShowStatus = FALSE ;
  235. else if (!bShowLegend)
  236. bShowStatus = FALSE ;
  237. else
  238. bShowStatus = TRUE ;
  239. yStatusHeight = bShowStatus ?
  240. ValuebarHeight (hWndGraphStatus) : 0 ;
  241. yLegendHeight = bShowLegend ?
  242. LegendHeight (hWndGraphLegend, yHeight) : 0 ;
  243. //=============================//
  244. // Update the status window //
  245. //=============================//
  246. if (bShowStatus)
  247. MoveWindow (hWndGraphStatus,
  248. 0, yHeight - yStatusHeight - yLegendHeight,
  249. xWidth, yStatusHeight,
  250. TRUE) ;
  251. WindowShow (hWndGraphStatus, bShowStatus) ;
  252. //=============================//
  253. // Update the legend window //
  254. //=============================//
  255. if (bShowLegend)
  256. MoveWindow (hWndGraphLegend,
  257. 0, yHeight - yLegendHeight,
  258. xWidth, yLegendHeight,
  259. TRUE) ;
  260. WindowShow (hWndGraphLegend, bShowLegend) ;
  261. //=============================//
  262. // Update the display window //
  263. //=============================//
  264. MoveWindow (hWndGraphDisplay,
  265. 0, 0,
  266. xWidth, yHeight - yStatusHeight - yLegendHeight,
  267. TRUE) ;
  268. SizeGraphDisplayComponents (hWndGraphDisplay) ;
  269. WindowInvalidate (hWndGraphDisplay) ;
  270. WindowShow (hWndGraphDisplay, TRUE) ;
  271. }