Removed the last of the C++ style comments. Adjusted the coding style a bit.
[reactos.git] / rosapps / taskmgr / graphctl.c
1 /*
2 * ReactOS Task Manager
3 *
4 * GraphCtrl.cpp
5 *
6 * Copyright (C) 2002 Robert Dickenson <robd@reactos.org>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23 #define WIN32_LEAN_AND_MEAN /* Exclude rarely-used stuff from Windows headers */
24 #include <windows.h>
25 #include <commctrl.h>
26 #include <stdlib.h>
27 #include <malloc.h>
28 #include <memory.h>
29 #include <tchar.h>
30 #include <stdio.h>
31
32 #include <math.h>
33 #include "graphctl.h"
34 #include "taskmgr.h"
35
36 #ifdef _DEBUG
37 #define new DEBUG_NEW
38 #undef THIS_FILE
39 static char THIS_FILE[] = __FILE__;
40 #endif
41
42
43 LONG OldGraphCtrlWndProc;
44
45 static void GraphCtrl_Init(TGraphCtrl* this)
46 {
47 int i;
48
49 this->m_hWnd = 0;
50 this->m_hParentWnd = 0;
51 this->m_dcGrid = 0;
52 this->m_dcPlot = 0;
53 this->m_bitmapOldGrid = 0;
54 this->m_bitmapOldPlot = 0;
55 this->m_bitmapGrid = 0;
56 this->m_bitmapPlot = 0;
57 this->m_brushBack = 0;
58
59 this->m_penPlot[0] = 0;
60 this->m_penPlot[1] = 0;
61 this->m_penPlot[2] = 0;
62 this->m_penPlot[3] = 0;
63
64 /* since plotting is based on a LineTo for each new point
65 * we need a starting point (i.e. a "previous" point)
66 * use 0.0 as the default first point.
67 * these are public member variables, and can be changed outside
68 * (after construction). Therefore m_perviousPosition could be set to
69 * a more appropriate value prior to the first call to SetPosition.
70 */
71 this->m_dPreviousPosition[0] = 0.0;
72 this->m_dPreviousPosition[1] = 0.0;
73 this->m_dPreviousPosition[2] = 0.0;
74 this->m_dPreviousPosition[3] = 0.0;
75
76 /* public variable for the number of decimal places on the y axis */
77 this->m_nYDecimals = 3;
78
79 /* set some initial values for the scaling until "SetRange" is called.
80 * these are protected varaibles and must be set with SetRange
81 * in order to ensure that m_dRange is updated accordingly
82 */
83 /* m_dLowerLimit = -10.0; */
84 /* m_dUpperLimit = 10.0; */
85 this->m_dLowerLimit = 0.0;
86 this->m_dUpperLimit = 100.0;
87 this->m_dRange = this->m_dUpperLimit - this->m_dLowerLimit; /* protected member variable */
88
89 /* m_nShiftPixels determines how much the plot shifts (in terms of pixels) */
90 /* with the addition of a new data point */
91 this->m_nShiftPixels = 4;
92 this->m_nHalfShiftPixels = this->m_nShiftPixels/2; /* protected */
93 this->m_nPlotShiftPixels = this->m_nShiftPixels + this->m_nHalfShiftPixels; /* protected */
94
95 /* background, grid and data colors */
96 /* these are public variables and can be set directly */
97 this->m_crBackColor = RGB( 0, 0, 0); /* see also SetBackgroundColor */
98 this->m_crGridColor = RGB( 0, 255, 255); /* see also SetGridColor */
99 this->m_crPlotColor[0] = RGB(255, 255, 255); /* see also SetPlotColor */
100 this->m_crPlotColor[1] = RGB(100, 255, 255); /* see also SetPlotColor */
101 this->m_crPlotColor[2] = RGB(255, 100, 255); /* see also SetPlotColor */
102 this->m_crPlotColor[3] = RGB(255, 255, 100); /* see also SetPlotColor */
103
104 /* protected variables */
105 for (i = 0; i < MAX_PLOTS; i++)
106 {
107 this->m_penPlot[i] = CreatePen(PS_SOLID, 0, this->m_crPlotColor[i]);
108 }
109 this->m_brushBack = CreateSolidBrush(this->m_crBackColor);
110
111 /* public member variables, can be set directly */
112 strcpy(this->m_strXUnitsString, "Samples"); /* can also be set with SetXUnits */
113 strcpy(this->m_strYUnitsString, "Y units"); /* can also be set with SetYUnits */
114
115 /* protected bitmaps to restore the memory DC's */
116 this->m_bitmapOldGrid = NULL;
117 this->m_bitmapOldPlot = NULL;
118 }
119
120 #if 0
121 TGraphCtrl::~TGraphCtrl()
122 {
123 /* just to be picky restore the bitmaps for the two memory dc's */
124 /* (these dc's are being destroyed so there shouldn't be any leaks) */
125 if (m_bitmapOldGrid != NULL) SelectObject(m_dcGrid, m_bitmapOldGrid);
126 if (m_bitmapOldPlot != NULL) SelectObject(m_dcPlot, m_bitmapOldPlot);
127 if (m_bitmapGrid != NULL) DeleteObject(m_bitmapGrid);
128 if (m_bitmapPlot != NULL) DeleteObject(m_bitmapPlot);
129 if (m_dcGrid != NULL) DeleteDC(m_dcGrid);
130 if (m_dcPlot != NULL) DeleteDC(m_dcPlot);
131 if (m_brushBack != NULL) DeleteObject(m_brushBack);
132 }
133 #endif
134
135 BOOL GraphCtrl_Create(TGraphCtrl* this, HWND hWnd, HWND hParentWnd, UINT nID)
136 {
137 BOOL result = 0;
138
139 GraphCtrl_Init(this);
140 this->m_hParentWnd = hParentWnd;
141 this->m_hWnd = hWnd;
142 GraphCtrl_Resize(this);
143 if (result != 0)
144 GraphCtrl_InvalidateCtrl(this);
145 return result;
146 }
147
148 void GraphCtrl_SetRange(TGraphCtrl* this, double dLower, double dUpper, int nDecimalPlaces)
149 {
150 /* ASSERT(dUpper > dLower); */
151 this->m_dLowerLimit = dLower;
152 this->m_dUpperLimit = dUpper;
153 this->m_nYDecimals = nDecimalPlaces;
154 this->m_dRange = this->m_dUpperLimit - this->m_dLowerLimit;
155 this->m_dVerticalFactor = (double)this->m_nPlotHeight / this->m_dRange;
156 /* clear out the existing garbage, re-start with a clean plot */
157 GraphCtrl_InvalidateCtrl(this);
158 }
159
160 #if 0
161 void TGraphCtrl::SetXUnits(const char* string)
162 {
163 strncpy(m_strXUnitsString, string, sizeof(m_strXUnitsString) - 1);
164 /* clear out the existing garbage, re-start with a clean plot */
165 InvalidateCtrl();
166 }
167
168 void TGraphCtrl::SetYUnits(const char* string)
169 {
170 strncpy(m_strYUnitsString, string, sizeof(m_strYUnitsString) - 1);
171 /* clear out the existing garbage, re-start with a clean plot */
172 InvalidateCtrl();
173 }
174 #endif
175
176 void GraphCtrl_SetGridColor(TGraphCtrl* this, COLORREF color)
177 {
178 this->m_crGridColor = color;
179 /* clear out the existing garbage, re-start with a clean plot */
180 GraphCtrl_InvalidateCtrl(this);
181 }
182
183 void GraphCtrl_SetPlotColor(TGraphCtrl* this, int plot, COLORREF color)
184 {
185 this->m_crPlotColor[plot] = color;
186 DeleteObject(this->m_penPlot[plot]);
187 this->m_penPlot[plot] = CreatePen(PS_SOLID, 0, this->m_crPlotColor[plot]);
188 /* clear out the existing garbage, re-start with a clean plot */
189 GraphCtrl_InvalidateCtrl(this);
190 }
191
192 void GraphCtrl_SetBackgroundColor(TGraphCtrl* this, COLORREF color)
193 {
194 this->m_crBackColor = color;
195 DeleteObject(this->m_brushBack);
196 this->m_brushBack = CreateSolidBrush(this->m_crBackColor);
197 /* clear out the existing garbage, re-start with a clean plot */
198 GraphCtrl_InvalidateCtrl(this);
199 }
200
201 void GraphCtrl_InvalidateCtrl(TGraphCtrl* this)
202 {
203 /* There is a lot of drawing going on here - particularly in terms of */
204 /* drawing the grid. Don't panic, this is all being drawn (only once) */
205 /* to a bitmap. The result is then BitBlt'd to the control whenever needed. */
206 int i, j;
207 int nCharacters;
208 int nTopGridPix, nMidGridPix, nBottomGridPix;
209
210 HPEN oldPen;
211 HPEN solidPen = CreatePen(PS_SOLID, 0, this->m_crGridColor);
212 /* HFONT axisFont, yUnitFont, oldFont; */
213 /* char strTemp[50]; */
214
215 /* in case we haven't established the memory dc's */
216 /* CClientDC dc(this); */
217 HDC dc = GetDC(this->m_hParentWnd);
218
219 /* if we don't have one yet, set up a memory dc for the grid */
220 if (this->m_dcGrid == NULL)
221 {
222 this->m_dcGrid = CreateCompatibleDC(dc);
223 this->m_bitmapGrid = CreateCompatibleBitmap(dc, this->m_nClientWidth, this->m_nClientHeight);
224 this->m_bitmapOldGrid = (HBITMAP)SelectObject(this->m_dcGrid, this->m_bitmapGrid);
225 }
226
227 SetBkColor(this->m_dcGrid, this->m_crBackColor);
228
229 /* fill the grid background */
230 FillRect(this->m_dcGrid, &this->m_rectClient, this->m_brushBack);
231
232 /* draw the plot rectangle: */
233 /* determine how wide the y axis scaling values are */
234 nCharacters = abs((int)log10(fabs(this->m_dUpperLimit)));
235 nCharacters = max(nCharacters, abs((int)log10(fabs(this->m_dLowerLimit))));
236
237 /* add the units digit, decimal point and a minus sign, and an extra space */
238 /* as well as the number of decimal places to display */
239 nCharacters = nCharacters + 4 + this->m_nYDecimals;
240
241 /* adjust the plot rectangle dimensions */
242 /* assume 6 pixels per character (this may need to be adjusted) */
243 /* m_rectPlot.left = m_rectClient.left + 6*(nCharacters); */
244 this->m_rectPlot.left = this->m_rectClient.left;
245 this->m_nPlotWidth = this->m_rectPlot.right - this->m_rectPlot.left;/* m_rectPlot.Width(); */
246
247 /* draw the plot rectangle */
248 oldPen = (HPEN)SelectObject(this->m_dcGrid, solidPen);
249 MoveToEx(this->m_dcGrid, this->m_rectPlot.left, this->m_rectPlot.top, NULL);
250 LineTo(this->m_dcGrid, this->m_rectPlot.right+1, this->m_rectPlot.top);
251 LineTo(this->m_dcGrid, this->m_rectPlot.right+1, this->m_rectPlot.bottom+1);
252 LineTo(this->m_dcGrid, this->m_rectPlot.left, this->m_rectPlot.bottom+1);
253 /* LineTo(m_dcGrid, m_rectPlot.left, m_rectPlot.top); */
254 SelectObject(this->m_dcGrid, oldPen);
255 DeleteObject(solidPen);
256
257 /* draw the dotted lines,
258 * use SetPixel instead of a dotted pen - this allows for a
259 * finer dotted line and a more "technical" look
260 */
261 nMidGridPix = (this->m_rectPlot.top + this->m_rectPlot.bottom)/2;
262 nTopGridPix = nMidGridPix - this->m_nPlotHeight/4;
263 nBottomGridPix = nMidGridPix + this->m_nPlotHeight/4;
264
265 for (i=this->m_rectPlot.left; i<this->m_rectPlot.right; i+=2)
266 {
267 SetPixel(this->m_dcGrid, i, nTopGridPix, this->m_crGridColor);
268 SetPixel(this->m_dcGrid, i, nMidGridPix, this->m_crGridColor);
269 SetPixel(this->m_dcGrid, i, nBottomGridPix, this->m_crGridColor);
270 }
271
272 for (i=this->m_rectPlot.left; i<this->m_rectPlot.right; i+=10)
273 {
274 for (j=this->m_rectPlot.top; j<this->m_rectPlot.bottom; j+=2)
275 {
276 SetPixel(this->m_dcGrid, i, j, this->m_crGridColor);
277 /* SetPixel(m_dcGrid, i, j, m_crGridColor); */
278 /* SetPixel(m_dcGrid, i, j, m_crGridColor); */
279 }
280 }
281
282 #if 0
283 /* create some fonts (horizontal and vertical) */
284 /* use a height of 14 pixels and 300 weight */
285 /* (these may need to be adjusted depending on the display) */
286 axisFont = CreateFont (14, 0, 0, 0, 300,
287 FALSE, FALSE, 0, ANSI_CHARSET,
288 OUT_DEFAULT_PRECIS,
289 CLIP_DEFAULT_PRECIS,
290 DEFAULT_QUALITY,
291 DEFAULT_PITCH|FF_SWISS, "Arial");
292 yUnitFont = CreateFont (14, 0, 900, 0, 300,
293 FALSE, FALSE, 0, ANSI_CHARSET,
294 OUT_DEFAULT_PRECIS,
295 CLIP_DEFAULT_PRECIS,
296 DEFAULT_QUALITY,
297 DEFAULT_PITCH|FF_SWISS, "Arial");
298
299 /* grab the horizontal font */
300 oldFont = (HFONT)SelectObject(m_dcGrid, axisFont);
301
302 /* y max */
303 SetTextColor(m_dcGrid, m_crGridColor);
304 SetTextAlign(m_dcGrid, TA_RIGHT|TA_TOP);
305 sprintf(strTemp, "%.*lf", m_nYDecimals, m_dUpperLimit);
306 TextOut(m_dcGrid, m_rectPlot.left-4, m_rectPlot.top, strTemp, _tcslen(strTemp));
307
308 /* y min */
309 SetTextAlign(m_dcGrid, TA_RIGHT|TA_BASELINE);
310 sprintf(strTemp, "%.*lf", m_nYDecimals, m_dLowerLimit);
311 TextOut(m_dcGrid, m_rectPlot.left-4, m_rectPlot.bottom, strTemp, _tcslen(strTemp));
312
313 /* x min */
314 SetTextAlign(m_dcGrid, TA_LEFT|TA_TOP);
315 TextOut(m_dcGrid, m_rectPlot.left, m_rectPlot.bottom+4, "0", 1);
316
317 /* x max */
318 SetTextAlign(m_dcGrid, TA_RIGHT|TA_TOP);
319 sprintf(strTemp, "%d", m_nPlotWidth/m_nShiftPixels);
320 TextOut(m_dcGrid, m_rectPlot.right, m_rectPlot.bottom+4, strTemp, _tcslen(strTemp));
321
322 /* x units */
323 SetTextAlign(m_dcGrid, TA_CENTER|TA_TOP);
324 TextOut(m_dcGrid, (m_rectPlot.left+m_rectPlot.right)/2,
325 m_rectPlot.bottom+4, m_strXUnitsString, _tcslen(m_strXUnitsString));
326
327 /* restore the font */
328 SelectObject(m_dcGrid, oldFont);
329
330 /* y units */
331 oldFont = (HFONT)SelectObject(m_dcGrid, yUnitFont);
332 SetTextAlign(m_dcGrid, TA_CENTER|TA_BASELINE);
333 TextOut(m_dcGrid, (m_rectClient.left+m_rectPlot.left)/2,
334 (m_rectPlot.bottom+m_rectPlot.top)/2, m_strYUnitsString, _tcslen(m_strYUnitsString));
335 SelectObject(m_dcGrid, oldFont);
336 #endif
337 /* at this point we are done filling the the grid bitmap, */
338 /* no more drawing to this bitmap is needed until the setting are changed */
339
340 /* if we don't have one yet, set up a memory dc for the plot */
341 if (this->m_dcPlot == NULL)
342 {
343 this->m_dcPlot = CreateCompatibleDC(dc);
344 this->m_bitmapPlot = CreateCompatibleBitmap(dc, this->m_nClientWidth, this->m_nClientHeight);
345 this->m_bitmapOldPlot = (HBITMAP)SelectObject(this->m_dcPlot, this->m_bitmapPlot);
346 }
347
348 /* make sure the plot bitmap is cleared */
349 SetBkColor(this->m_dcPlot, this->m_crBackColor);
350 FillRect(this->m_dcPlot, &this->m_rectClient, this->m_brushBack);
351
352 /* finally, force the plot area to redraw */
353 InvalidateRect(this->m_hParentWnd, &this->m_rectClient, TRUE);
354 ReleaseDC(this->m_hParentWnd, dc);
355 }
356
357 double GraphCtrl_AppendPoint(TGraphCtrl* this,
358 double dNewPoint0, double dNewPoint1,
359 double dNewPoint2, double dNewPoint3)
360 {
361 /* append a data point to the plot & return the previous point */
362 double dPrevious;
363
364 dPrevious = this->m_dCurrentPosition[0];
365 this->m_dCurrentPosition[0] = dNewPoint0;
366 this->m_dCurrentPosition[1] = dNewPoint1;
367 this->m_dCurrentPosition[2] = dNewPoint2;
368 this->m_dCurrentPosition[3] = dNewPoint3;
369 GraphCtrl_DrawPoint(this);
370 /* Invalidate(); */
371 return dPrevious;
372 }
373
374 void GraphCtrl_Paint(TGraphCtrl* this, HWND hWnd, HDC dc)
375 {
376 HDC memDC;
377 HBITMAP memBitmap;
378 HBITMAP oldBitmap; /* bitmap originally found in CMemDC */
379
380 /* RECT rcClient; */
381 /* GetClientRect(hWnd, &rcClient); */
382 /* FillSolidRect(dc, &rcClient, RGB(255, 0, 255)); */
383 /* m_nClientWidth = rcClient.right - rcClient.left; */
384 /* m_nClientHeight = rcClient.bottom - rcClient.top; */
385
386 /* no real plotting work is performed here, */
387 /* just putting the existing bitmaps on the client */
388
389 /* to avoid flicker, establish a memory dc, draw to it */
390 /* and then BitBlt it to the client */
391 memDC = CreateCompatibleDC(dc);
392 memBitmap = (HBITMAP)CreateCompatibleBitmap(dc, this->m_nClientWidth, this->m_nClientHeight);
393 oldBitmap = (HBITMAP)SelectObject(memDC, memBitmap);
394
395 if (memDC != NULL)
396 {
397 /* first drop the grid on the memory dc */
398 BitBlt(memDC, 0, 0, this->m_nClientWidth, this->m_nClientHeight, this->m_dcGrid, 0, 0, SRCCOPY);
399 /* now add the plot on top as a "pattern" via SRCPAINT. */
400 /* works well with dark background and a light plot */
401 BitBlt(memDC, 0, 0, this->m_nClientWidth, this->m_nClientHeight, this->m_dcPlot, 0, 0, SRCPAINT); /* SRCPAINT */
402 /* finally send the result to the display */
403 BitBlt(dc, 0, 0, this->m_nClientWidth, this->m_nClientHeight, memDC, 0, 0, SRCCOPY);
404 }
405 SelectObject(memDC, oldBitmap);
406 DeleteObject(memBitmap);
407 DeleteDC(memDC);
408 }
409
410 void GraphCtrl_DrawPoint(TGraphCtrl* this)
411 {
412 /* this does the work of "scrolling" the plot to the left
413 * and appending a new data point all of the plotting is
414 * directed to the memory based bitmap associated with m_dcPlot
415 * the will subsequently be BitBlt'd to the client in Paint
416 */
417 int currX, prevX, currY, prevY;
418 HPEN oldPen;
419 RECT rectCleanUp;
420 int i;
421
422 if (this->m_dcPlot != NULL)
423 {
424 /* shift the plot by BitBlt'ing it to itself
425 * note: the m_dcPlot covers the entire client
426 * but we only shift bitmap that is the size
427 * of the plot rectangle
428 * grab the right side of the plot (exluding m_nShiftPixels on the left)
429 * move this grabbed bitmap to the left by m_nShiftPixels
430 */
431 BitBlt(this->m_dcPlot, this->m_rectPlot.left, this->m_rectPlot.top+1,
432 this->m_nPlotWidth, this->m_nPlotHeight, this->m_dcPlot,
433 this->m_rectPlot.left+this->m_nShiftPixels, this->m_rectPlot.top+1,
434 SRCCOPY);
435
436 /* establish a rectangle over the right side of plot */
437 /* which now needs to be cleaned up proir to adding the new point */
438 rectCleanUp = this->m_rectPlot;
439 rectCleanUp.left = rectCleanUp.right - this->m_nShiftPixels;
440
441 /* fill the cleanup area with the background */
442 FillRect(this->m_dcPlot, &rectCleanUp, this->m_brushBack);
443
444 /* draw the next line segement */
445 for (i = 0; i < MAX_PLOTS; i++)
446 {
447 /* grab the plotting pen */
448 oldPen = (HPEN)SelectObject(this->m_dcPlot, this->m_penPlot[i]);
449
450 /* move to the previous point */
451 prevX = this->m_rectPlot.right-this->m_nPlotShiftPixels;
452 prevY = this->m_rectPlot.bottom -
453 (long)((this->m_dPreviousPosition[i] - this->m_dLowerLimit) * this->m_dVerticalFactor);
454 MoveToEx(this->m_dcPlot, prevX, prevY, NULL);
455
456 /* draw to the current point */
457 currX = this->m_rectPlot.right-this->m_nHalfShiftPixels;
458 currY = this->m_rectPlot.bottom -
459 (long)((this->m_dCurrentPosition[i] - this->m_dLowerLimit) * this->m_dVerticalFactor);
460 LineTo(this->m_dcPlot, currX, currY);
461
462 /* Restore the pen */
463 SelectObject(this->m_dcPlot, oldPen);
464
465 /* if the data leaks over the upper or lower plot boundaries
466 * fill the upper and lower leakage with the background
467 * this will facilitate clipping on an as needed basis
468 * as opposed to always calling IntersectClipRect
469 */
470 if ((prevY <= this->m_rectPlot.top) || (currY <= this->m_rectPlot.top))
471 {
472 RECT rc;
473 rc.bottom = this->m_rectPlot.top+1;
474 rc.left = prevX;
475 rc.right = currX+1;
476 rc.top = this->m_rectClient.top;
477 FillRect(this->m_dcPlot, &rc, this->m_brushBack);
478 }
479 if ((prevY >= this->m_rectPlot.bottom) || (currY >= this->m_rectPlot.bottom))
480 {
481 RECT rc;
482 rc.bottom = this->m_rectClient.bottom+1;
483 rc.left = prevX;
484 rc.right = currX+1;
485 rc.top = this->m_rectPlot.bottom+1;
486 /* RECT rc(prevX, m_rectPlot.bottom+1, currX+1, m_rectClient.bottom+1); */
487 FillRect(this->m_dcPlot, &rc, this->m_brushBack);
488 }
489
490 /* store the current point for connection to the next point */
491 this->m_dPreviousPosition[i] = this->m_dCurrentPosition[i];
492 }
493 }
494 }
495
496 void GraphCtrl_Resize(TGraphCtrl* this)
497 {
498 /* NOTE: Resize automatically gets called during the setup of the control */
499 GetClientRect(this->m_hWnd, &this->m_rectClient);
500
501 /* set some member variables to avoid multiple function calls */
502 this->m_nClientHeight = this->m_rectClient.bottom - this->m_rectClient.top;/* m_rectClient.Height(); */
503 this->m_nClientWidth = this->m_rectClient.right - this->m_rectClient.left;/* m_rectClient.Width(); */
504
505 /* the "left" coordinate and "width" will be modified in */
506 /* InvalidateCtrl to be based on the width of the y axis scaling */
507 #if 0
508 this->m_rectPlot.left = 20;
509 this->m_rectPlot.top = 10;
510 this->m_rectPlot.right = this->m_rectClient.right-10;
511 this->m_rectPlot.bottom = this->m_rectClient.bottom-25;
512 #else
513 this->m_rectPlot.left = 0;
514 this->m_rectPlot.top = -1;
515 this->m_rectPlot.right = this->m_rectClient.right-0;
516 this->m_rectPlot.bottom = this->m_rectClient.bottom-0;
517 #endif
518
519 /* set some member variables to avoid multiple function calls */
520 this->m_nPlotHeight = this->m_rectPlot.bottom - this->m_rectPlot.top;/* m_rectPlot.Height(); */
521 this->m_nPlotWidth = this->m_rectPlot.right - this->m_rectPlot.left;/* m_rectPlot.Width(); */
522
523 /* set the scaling factor for now, this can be adjusted */
524 /* in the SetRange functions */
525 this->m_dVerticalFactor = (double)this->m_nPlotHeight / this->m_dRange;
526 }
527
528 #if 0
529 void TGraphCtrl::Reset()
530 {
531 /* to clear the existing data (in the form of a bitmap) */
532 /* simply invalidate the entire control */
533 InvalidateCtrl();
534 }
535 #endif
536
537 extern TGraphCtrl PerformancePageCpuUsageHistoryGraph;
538 extern TGraphCtrl PerformancePageMemUsageHistoryGraph;
539 extern HWND hPerformancePageCpuUsageHistoryGraph;
540 extern HWND hPerformancePageMemUsageHistoryGraph;
541
542 LRESULT CALLBACK GraphCtrl_WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
543 {
544 RECT rcClient;
545 HDC hdc;
546 PAINTSTRUCT ps;
547
548 switch (message)
549 {
550 case WM_ERASEBKGND:
551 return TRUE;
552 /*
553 * Filter out mouse & keyboard messages
554 */
555 /* case WM_APPCOMMAND: */
556 case WM_CAPTURECHANGED:
557 case WM_LBUTTONDBLCLK:
558 case WM_LBUTTONDOWN:
559 case WM_LBUTTONUP:
560 case WM_MBUTTONDBLCLK:
561 case WM_MBUTTONDOWN:
562 case WM_MBUTTONUP:
563 case WM_MOUSEACTIVATE:
564 case WM_MOUSEHOVER:
565 case WM_MOUSELEAVE:
566 case WM_MOUSEMOVE:
567 /* case WM_MOUSEWHEEL: */
568 case WM_NCHITTEST:
569 case WM_NCLBUTTONDBLCLK:
570 case WM_NCLBUTTONDOWN:
571 case WM_NCLBUTTONUP:
572 case WM_NCMBUTTONDBLCLK:
573 case WM_NCMBUTTONDOWN:
574 case WM_NCMBUTTONUP:
575 /* case WM_NCMOUSEHOVER: */
576 /* case WM_NCMOUSELEAVE: */
577 case WM_NCMOUSEMOVE:
578 case WM_NCRBUTTONDBLCLK:
579 case WM_NCRBUTTONDOWN:
580 case WM_NCRBUTTONUP:
581 /* case WM_NCXBUTTONDBLCLK: */
582 /* case WM_NCXBUTTONDOWN: */
583 /* case WM_NCXBUTTONUP: */
584 case WM_RBUTTONDBLCLK:
585 case WM_RBUTTONDOWN:
586 case WM_RBUTTONUP:
587 /* case WM_XBUTTONDBLCLK: */
588 /* case WM_XBUTTONDOWN: */
589 /* case WM_XBUTTONUP: */
590 case WM_ACTIVATE:
591 case WM_CHAR:
592 case WM_DEADCHAR:
593 case WM_GETHOTKEY:
594 case WM_HOTKEY:
595 case WM_KEYDOWN:
596 case WM_KEYUP:
597 case WM_KILLFOCUS:
598 case WM_SETFOCUS:
599 case WM_SETHOTKEY:
600 case WM_SYSCHAR:
601 case WM_SYSDEADCHAR:
602 case WM_SYSKEYDOWN:
603 case WM_SYSKEYUP:
604 return 0;
605
606 case WM_NCCALCSIZE:
607 return 0;
608
609 case WM_SIZE:
610 if (hWnd == hPerformancePageMemUsageHistoryGraph)
611 {
612 GraphCtrl_Resize(&PerformancePageMemUsageHistoryGraph);
613 GraphCtrl_InvalidateCtrl(&PerformancePageMemUsageHistoryGraph);
614 }
615 if (hWnd == hPerformancePageCpuUsageHistoryGraph)
616 {
617 GraphCtrl_Resize(&PerformancePageCpuUsageHistoryGraph);
618 GraphCtrl_InvalidateCtrl(&PerformancePageCpuUsageHistoryGraph);
619 }
620 return 0;
621
622 case WM_PAINT:
623 hdc = BeginPaint(hWnd, &ps);
624 GetClientRect(hWnd, &rcClient);
625 if (hWnd == hPerformancePageMemUsageHistoryGraph)
626 GraphCtrl_Paint(&PerformancePageMemUsageHistoryGraph, hWnd, hdc);
627 if (hWnd == hPerformancePageCpuUsageHistoryGraph)
628 GraphCtrl_Paint(&PerformancePageCpuUsageHistoryGraph, hWnd, hdc);
629 EndPaint(hWnd, &ps);
630 return 0;
631 }
632
633 /*
634 * We pass on all non-handled messages
635 */
636 return CallWindowProc((WNDPROC)OldGraphCtrlWndProc, hWnd, message, wParam, lParam);
637 }