Windows NT 4.0 source code leak
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.

332 lines
10 KiB

4 years ago
  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 static OnCreate (HWND hWnd)
  49. { // OnCreate
  50. hWndGraphDisplay = CreateGraphDisplayWindow (hWnd) ;
  51. hWndGraphLegend = CreateGraphLegendWindow (hWnd) ;
  52. hWndGraphStatus = CreateGraphStatusWindow (hWnd) ;
  53. } // OnCreate
  54. void static OnPaint (HWND hWnd)
  55. {
  56. HDC hDC ;
  57. PAINTSTRUCT ps ;
  58. hDC = BeginPaint (hWnd, &ps) ;
  59. EndPaint (hWnd, &ps) ;
  60. }
  61. void static OnSize (HWND hWnd, int xWidth, int yHeight)
  62. { // OnSize
  63. SizeGraphComponents (hWnd) ;
  64. } // OnSize
  65. //==========================================================================//
  66. // Message Handlers //
  67. //==========================================================================//
  68. LRESULT APIENTRY GraphWndProc (HWND hWnd,
  69. WORD wMsg,
  70. DWORD wParam,
  71. LONG lParam)
  72. { // GraphWndProc
  73. BOOL bCallDefProc ;
  74. LRESULT lReturnValue ;
  75. bCallDefProc = FALSE ;
  76. lReturnValue = 0L ;
  77. switch (wMsg)
  78. { // switch
  79. case WM_CREATE:
  80. OnCreate (hWnd) ;
  81. break ;
  82. case WM_LBUTTONDBLCLK:
  83. SendMessage (hWndMain, WM_LBUTTONDBLCLK, wParam, lParam) ;
  84. break ;
  85. case WM_PAINT:
  86. OnPaint (hWnd) ;
  87. break ;
  88. case WM_SIZE:
  89. OnSize (hWnd, LOWORD (lParam), HIWORD (lParam)) ;
  90. break ;
  91. default:
  92. bCallDefProc = TRUE ;
  93. } // switch
  94. if (bCallDefProc)
  95. lReturnValue = DefWindowProc (hWnd, wMsg, wParam, lParam) ;
  96. return (lReturnValue);
  97. } // GraphWndProc
  98. BOOL GraphInitializeApplication (void)
  99. /*
  100. Note: There is no background brush set for the MainWindow
  101. class so that the main window is never erased. The
  102. client area of MainWindow is always covered by one
  103. of the view windows. If we erase it, it would just
  104. flicker needlessly.
  105. */
  106. { // GraphInitializeApplication
  107. BOOL bSuccess ;
  108. WNDCLASS wc ;
  109. //=============================//
  110. // Register GraphWindow class //
  111. //=============================//
  112. wc.style = dwGraphClassStyle ;
  113. wc.lpfnWndProc = (WNDPROC) GraphWndProc ;
  114. wc.hInstance = hInstance ;
  115. wc.cbClsExtra = iGraphWindowExtra ;
  116. wc.cbWndExtra = iGraphClassExtra ;
  117. wc.hIcon = NULL ;
  118. wc.hCursor = LoadCursor(NULL, IDC_ARROW) ;
  119. wc.hbrBackground = NULL ; // see note above
  120. wc.lpszMenuName = NULL ;
  121. wc.lpszClassName = szGraphWindowClass ;
  122. bSuccess = RegisterClass (&wc) ;
  123. //=============================//
  124. // Register Child classes //
  125. //=============================//
  126. if (bSuccess)
  127. bSuccess = GraphDisplayInitializeApplication () ;
  128. if (bSuccess)
  129. bSuccess = GraphLegendInitializeApplication () ;
  130. if (bSuccess)
  131. bSuccess = GraphStatusInitializeApplication () ;
  132. return (bSuccess) ;
  133. } // GraphInitializeApplication
  134. HWND CreateGraphWindow (HWND hWndParent)
  135. /*
  136. Effect: Create the graph window. This window is a child of
  137. hWndMain and is a container for the graph data,
  138. graph label, graph legend, and graph status windows.
  139. Note: We dont worry about the size here, as this window
  140. will be resized whenever the main window is resized.
  141. */
  142. {
  143. return (CreateWindow (szGraphWindowClass, // window class
  144. NULL, // caption
  145. dwGraphWindowStyle, // style for window
  146. 0, 0, // initial position
  147. 0, 0, // initial size
  148. hWndParent, // parent
  149. NULL, // menu
  150. hInstance, // program instance
  151. NULL)) ; // user-supplied data
  152. }
  153. void SizeGraphComponents (HWND hWnd)
  154. /*
  155. Effect: Move and show the various components of the graph to
  156. fill the size (xWidth x yHeight). Take into account
  157. whether the user wants to show the legend or status
  158. bars. Also take into account if we have room for these
  159. items.
  160. Internals: If the user doesn't want the status or legend windows,
  161. they aren't shown. Also, if the user wanted the status
  162. window but not the legend window, the status window is
  163. not shown.
  164. We may disregard the user's desire for the legend or
  165. status bar if there is not room. In particular, a legend
  166. window has a minimum width (LegendMinWidth ()) and a
  167. minimum height (LegendMinHeight ()). These values are
  168. fixed for a given session of perfmon. It also has a
  169. preferred height, which takes into consideration the
  170. size of the graph window and the number of items in
  171. the legend. This value is returned by LegendHeight().
  172. We don't show the legend if its minimum height would
  173. take up more than half the graph height.
  174. If we feel we don't have room for the legend, we don't
  175. show the status window either.
  176. See Also: LegendMinWidth, LegendMinHeight, LegendHeight,
  177. ValuebarHeight.
  178. Called By: OnSize, any other function that may remove or add one
  179. of the graph components.
  180. */
  181. { // SizeGraphComponents
  182. RECT rectClient ;
  183. BOOL bShowLegend ;
  184. BOOL bShowStatus ;
  185. int yStatusHeight ;
  186. int yLegendHeight ;
  187. int xWidth ;
  188. int yHeight ;
  189. GetClientRect (hWnd, &rectClient) ;
  190. xWidth = rectClient.right - rectClient.left ;
  191. yHeight = rectClient.bottom - rectClient.top ;
  192. // if the graph window has no size, neither will its children.
  193. if (!xWidth || !yHeight)
  194. return ;
  195. //=============================//
  196. // Show the Legend Window? //
  197. //=============================//
  198. if (!pGraphs->gOptions.bLegendChecked)
  199. bShowLegend = FALSE ;
  200. else if (xWidth < LegendMinWidth (hWndGraphLegend))
  201. bShowLegend = FALSE ;
  202. else if (yHeight < 5 * LegendMinHeight (hWndGraphLegend))
  203. bShowLegend = FALSE ;
  204. else
  205. bShowLegend = TRUE ;
  206. //=============================//
  207. // Show the Status Window? //
  208. //=============================//
  209. if (!pGraphs->gOptions.bStatusBarChecked)
  210. bShowStatus = FALSE ;
  211. else if (!bShowLegend)
  212. bShowStatus = FALSE ;
  213. else
  214. bShowStatus = TRUE ;
  215. yStatusHeight = bShowStatus ?
  216. ValuebarHeight (hWndGraphStatus) : 0 ;
  217. yLegendHeight = bShowLegend ?
  218. LegendHeight (hWndGraphLegend, yHeight) : 0 ;
  219. //=============================//
  220. // Update the status window //
  221. //=============================//
  222. if (bShowStatus)
  223. MoveWindow (hWndGraphStatus,
  224. 0, yHeight - yStatusHeight - yLegendHeight,
  225. xWidth, yStatusHeight,
  226. TRUE) ;
  227. WindowShow (hWndGraphStatus, bShowStatus) ;
  228. //=============================//
  229. // Update the legend window //
  230. //=============================//
  231. if (bShowLegend)
  232. MoveWindow (hWndGraphLegend,
  233. 0, yHeight - yLegendHeight,
  234. xWidth, yLegendHeight,
  235. TRUE) ;
  236. WindowShow (hWndGraphLegend, bShowLegend) ;
  237. //=============================//
  238. // Update the display window //
  239. //=============================//
  240. MoveWindow (hWndGraphDisplay,
  241. 0, 0,
  242. xWidth, yHeight - yStatusHeight - yLegendHeight,
  243. TRUE) ;
  244. SizeGraphDisplayComponents (hWndGraphDisplay) ;
  245. WindowInvalidate (hWndGraphDisplay) ;
  246. WindowShow (hWndGraphDisplay, TRUE) ;
  247. } // SizeGraphComponents