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