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