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.

414 lines
11 KiB

  1. /*
  2. ==============================================================================
  3. Application:
  4. Microsoft Windows NT (TM) Performance Monitor
  5. File:
  6. Command.c -- PerfmonCommand routine and helpers.
  7. This file contains the PerfmonCommand routine, which handles
  8. all of the user's menu selections.
  9. Copyright 1992-1993, Microsoft Corporation. All Rights Reserved.
  10. Microsoft Confidential.
  11. ==============================================================================
  12. */
  13. //==========================================================================//
  14. // Includes //
  15. //==========================================================================//
  16. #include "stdio.h"
  17. #include "setedit.h"
  18. #include "command.h" // External declarations for this file
  19. #include <shellapi.h> // for ShellAbout
  20. #include "cderr.h"
  21. #include "dialogs.h"
  22. #include "fileopen.h" // for FileOpen
  23. #include "grafdata.h" // for ChartDeleteLine ClearGraphDisplay & ToggleGraphRefresh
  24. #include "init.h" // for PerfmonClose
  25. #include "legend.h"
  26. #include "status.h" // for StatusUpdateIcons
  27. #include "toolbar.h" // for ToolbarDepressButton
  28. #include "utils.h"
  29. #include "perfmops.h" // for SaveWorkspace
  30. int static deltax ;
  31. int static deltay ;
  32. #define ABOUT_TIMER_ID 10
  33. INT_PTR
  34. FAR
  35. WINAPI
  36. AboutDlgProc (
  37. HWND hDlg,
  38. UINT iMessage,
  39. WPARAM wParam,
  40. LPARAM lParam)
  41. {
  42. BOOL bHandled ;
  43. bHandled = TRUE ;
  44. switch (iMessage) {
  45. case WM_INITDIALOG:
  46. deltax = 0 ;
  47. deltay = 0 ;
  48. dwCurrentDlgID = 0 ;
  49. SetTimer(hDlg, ABOUT_TIMER_ID, 1000, NULL) ;
  50. WindowCenter (hDlg) ;
  51. return (TRUE) ;
  52. case WM_TIMER:
  53. deltax += 2 ;
  54. if (deltax > 60)
  55. deltax = 0 ;
  56. deltay += 5 ;
  57. if (deltay > 60)
  58. deltay = 0 ;
  59. WindowInvalidate (DialogControl (hDlg, 524)) ;
  60. break ;
  61. case WM_DRAWITEM:
  62. {
  63. int xPos, yPos ;
  64. LPDRAWITEMSTRUCT lpItem ;
  65. lpItem = (LPDRAWITEMSTRUCT) lParam ;
  66. xPos = lpItem->rcItem.left + deltax ;
  67. yPos = lpItem->rcItem.top + deltay ;
  68. DrawIcon (lpItem->hDC, xPos, yPos, hIcon) ;
  69. }
  70. break ;
  71. case WM_CLOSE:
  72. dwCurrentDlgID = 0 ;
  73. KillTimer (hDlg, ABOUT_TIMER_ID) ;
  74. EndDialog (hDlg, 1) ;
  75. break ;
  76. case WM_COMMAND:
  77. switch (wParam) {
  78. case IDD_OK:
  79. dwCurrentDlgID = 0 ;
  80. EndDialog (hDlg, 1) ;
  81. break ;
  82. default:
  83. bHandled = FALSE ;
  84. break;
  85. }
  86. break;
  87. default:
  88. bHandled = FALSE ;
  89. break ;
  90. }
  91. return (bHandled) ;
  92. }
  93. //==========================================================================//
  94. // Local Functions //
  95. //==========================================================================//
  96. void
  97. ChangeView (
  98. HWND hWnd,
  99. int iNewView
  100. )
  101. {
  102. // only Chart view
  103. iPerfmonView = IDM_VIEWCHART ;
  104. WindowShow (hWndGraph, TRUE) ;
  105. DrawMenuBar(hWnd) ;
  106. StatusLineReady (hWndStatus) ;
  107. }
  108. //==========================================================================//
  109. // Message Handlers //
  110. //==========================================================================//
  111. void
  112. ViewChart (
  113. HWND hWnd
  114. )
  115. {
  116. if (Options.bMenubar)
  117. SetMenu (hWnd, hMenuChart) ;
  118. ChangeView (hWnd, IDM_VIEWCHART) ;
  119. }
  120. #ifdef KEEP_MANUALREFRESH
  121. void
  122. ToggleRefresh (
  123. HWND hWnd
  124. )
  125. {
  126. BOOL bRefresh ;
  127. bRefresh = ToggleGraphRefresh (hWndGraph) ;
  128. MenuCheck (GetMenu (hWnd), IDM_OPTIONSMANUALREFRESH, bRefresh) ;
  129. }
  130. #endif
  131. //==========================================================================//
  132. // Exported Functions //
  133. //==========================================================================//
  134. BOOL
  135. PerfmonCommand (
  136. HWND hWnd,
  137. WPARAM wParam,
  138. LPARAM lParam
  139. )
  140. /*
  141. Effect: Respond to the user's menu selection, found in wParam.
  142. In particular, branch to the appropriate OnXXX function
  143. to perform the action associated with each command.
  144. Called By: MainWndProc (perfmon.c), in response to a WM_COMMAND
  145. message.
  146. */
  147. {
  148. PLINESTRUCT pLine ;
  149. BOOL bPrepareMenu = TRUE ;
  150. switch (LOWORD (wParam)) {
  151. //=============================//
  152. // Toolbar Commands //
  153. //=============================//
  154. case IDM_TOOLBARADD:
  155. bPrepareMenu = FALSE ;
  156. SendMessage (hWnd, WM_COMMAND, IDM_EDITADDCHART, lParam) ;
  157. break ;
  158. case IDM_TOOLBARMODIFY:
  159. bPrepareMenu = FALSE ;
  160. SendMessage (hWnd, WM_COMMAND, IDM_EDITMODIFYCHART, lParam) ;
  161. break ;
  162. case IDM_TOOLBARDELETE:
  163. bPrepareMenu = FALSE ;
  164. SendMessage (hWnd, WM_COMMAND, IDM_EDITDELETECHART, lParam) ;
  165. break ;
  166. case IDM_TOOLBARREFRESH:
  167. bPrepareMenu = FALSE ;
  168. SendMessage (hWnd, WM_COMMAND, IDM_OPTIONSREFRESHNOWCHART, lParam) ;
  169. break ;
  170. case IDM_TOOLBAROPTIONS:
  171. bPrepareMenu = FALSE ;
  172. SendMessage (hWnd, WM_COMMAND, IDM_OPTIONSCHART, lParam) ;
  173. break ;
  174. //=============================//
  175. // "File" Commands //
  176. //=============================//
  177. case IDM_FILENEWCHART:
  178. if (QuerySaveChart (hWnd, pGraphs))
  179. ResetGraphView (hWndGraph) ;
  180. break ;
  181. case IDM_FILEOPENCHART:
  182. if (QuerySaveChart (hWnd, pGraphs))
  183. FileOpen (hWndGraph, IDS_CHARTFILE, NULL) ;
  184. break ;
  185. case IDM_FILESAVECHART:
  186. case IDM_FILESAVEASCHART:
  187. bPrepareMenu = FALSE ;
  188. SaveChart (hWndGraph, 0,
  189. (LOWORD (wParam) == IDM_FILESAVEASCHART) ? TRUE : FALSE) ;
  190. break;
  191. case IDM_FILEEXIT:
  192. if (QuerySaveChart (hWnd, pGraphs)) {
  193. PerfmonClose (hWnd) ;
  194. bPrepareMenu = FALSE ;
  195. }
  196. break ;
  197. //=============================//
  198. // "Edit" Commands //
  199. //=============================//
  200. case IDM_EDITADDCHART:
  201. AddChart (hWnd) ;
  202. break;
  203. case IDM_EDITDELETECHART:
  204. pLine = CurrentGraphLine (hWndGraph) ;
  205. if (pLine)
  206. ChartDeleteLine(pGraphs, pLine) ;
  207. break ;
  208. case IDM_EDITMODIFYCHART:
  209. EditChart (hWnd) ;
  210. break ;
  211. //=============================//
  212. // "Options" Commands //
  213. //=============================//
  214. case IDM_OPTIONSCHART:
  215. DialogBox(hInstance, idDlgChartOptions, hWnd, GraphOptionDlg);
  216. break;
  217. case IDM_OPTIONSDISPLAYMENU:
  218. // ShowPerfmonMenu will update Options.bMenubar..
  219. ShowPerfmonMenu (!Options.bMenubar) ;
  220. break ;
  221. case IDM_OPTIONSDISPLAYTOOL:
  222. Options.bToolbar = !Options.bToolbar ;
  223. SizePerfmonComponents () ;
  224. break ;
  225. case IDM_OPTIONSDISPLAYSTATUS:
  226. Options.bStatusbar = !Options.bStatusbar ;
  227. SizePerfmonComponents () ;
  228. break ;
  229. case IDM_OPTIONSDISPLAYONTOP:
  230. Options.bAlwaysOnTop = !Options.bAlwaysOnTop ;
  231. // WindowSetTopmost (hWndMain, Options.bAlwaysOnTop) ;
  232. break ;
  233. //=============================//
  234. // "Help" Commands //
  235. //=============================//
  236. case IDM_HELPABOUT:
  237. {
  238. TCHAR szApplication [WindowCaptionLen] ;
  239. bPrepareMenu = FALSE ;
  240. if (GetKeyState(VK_SHIFT) < 0 && GetKeyState(VK_CONTROL) < 0) {
  241. DialogBox (hInstance, idDlgAbout, hWndMain, AboutDlgProc) ;
  242. } else {
  243. StringLoad (IDS_APPNAME, szApplication) ;
  244. ShellAbout (hWnd, szApplication, NULL, hIcon) ;
  245. }
  246. }
  247. break ;
  248. //======================================//
  249. // Generic messages from ACCELERATORS //
  250. //======================================//
  251. case IDM_FILEOPENFILE:
  252. bPrepareMenu = FALSE ;
  253. SendMessage (hWnd, WM_COMMAND, IDM_FILEOPENCHART, lParam) ;
  254. break ;
  255. case IDM_FILESAVEFILE:
  256. bPrepareMenu = FALSE ;
  257. SendMessage (hWnd, WM_COMMAND, IDM_FILESAVECHART, lParam) ;
  258. break ;
  259. case IDM_FILESAVEASFILE:
  260. bPrepareMenu = FALSE ;
  261. SendMessage (hWnd, WM_COMMAND, IDM_FILESAVEASCHART, lParam) ;
  262. break ;
  263. case IDM_TOOLBARID:
  264. // msg from the toolbar control
  265. bPrepareMenu = FALSE ;
  266. OnToolbarHit (wParam, lParam) ;
  267. break ;
  268. default:
  269. return (FALSE) ;
  270. }
  271. if (bPrepareMenu) {
  272. PrepareMenu (GetMenu (hWnd)) ;
  273. }
  274. return (TRUE) ;
  275. }
  276. void
  277. PrepareMenu (
  278. HMENU hMenu
  279. )
  280. {
  281. BOOL bPlayingLog ;
  282. BOOL bCurrentLine ;
  283. BOOL bManualRefresh ;
  284. BOOL bLogCollecting ;
  285. BOOL bRefresh ;
  286. // hMenu is NULL when the menu bar display option is off.
  287. // In that case, we still have to enable/disable all tool buttons
  288. // So, I have commented out the next 2 lines...
  289. // if (!hMenu)
  290. // return ;
  291. bLogCollecting = FALSE ;
  292. bPlayingLog = FALSE ;
  293. bCurrentLine = (CurrentGraphLine (hWndGraph) != NULL) ;
  294. bRefresh = GraphRefresh (hWndGraph) ;
  295. bManualRefresh = !bPlayingLog && bCurrentLine ;
  296. if (hMenu) {
  297. MenuCheck (hMenu, IDM_VIEWCHART, TRUE) ;
  298. MenuEnableItem (hMenu, IDM_FILEEXPORTCHART, bCurrentLine) ;
  299. MenuEnableItem (hMenu, IDM_EDITMODIFYCHART, bCurrentLine) ;
  300. MenuEnableItem (hMenu, IDM_EDITDELETECHART, bCurrentLine) ;
  301. }
  302. ToolbarEnableButton (hWndToolbar, EditTool,
  303. bCurrentLine &&
  304. (iPerfmonView != IDM_VIEWREPORT &&
  305. iPerfmonView != IDM_VIEWLOG)) ;
  306. ToolbarEnableButton (hWndToolbar, DeleteTool, bCurrentLine) ;
  307. // None of the alert or report options make sense when playing back a log.
  308. ToolbarEnableButton (hWndToolbar,
  309. OptionsTool,
  310. !bPlayingLog ||
  311. iPerfmonView != IDM_VIEWREPORT) ;
  312. if (hMenu) {
  313. // check/uncheck all the display options
  314. MenuCheck (hMenu, IDM_OPTIONSDISPLAYMENU, Options.bMenubar) ;
  315. MenuCheck (hMenu, IDM_OPTIONSDISPLAYTOOL, Options.bToolbar) ;
  316. MenuCheck (hMenu, IDM_OPTIONSDISPLAYSTATUS, Options.bStatusbar) ;
  317. MenuCheck (hMenu, IDM_OPTIONSDISPLAYONTOP, Options.bAlwaysOnTop) ;
  318. }
  319. }