[APPLICATIONS]
[reactos.git] / reactos / base / applications / taskmgr / graphctl.c
1 /*
2 * ReactOS Task Manager
3 *
4 * graphctl.c
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 along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 */
22
23 #include "precomp.h"
24
25 #include <math.h>
26
27 WNDPROC OldGraphCtrlWndProc;
28
29 static void GraphCtrl_Init(TGraphCtrl* this)
30 {
31 int i;
32
33 this->m_hWnd = 0;
34 this->m_hParentWnd = 0;
35 this->m_dcGrid = 0;
36 this->m_dcPlot = 0;
37 this->m_bitmapOldGrid = 0;
38 this->m_bitmapOldPlot = 0;
39 this->m_bitmapGrid = 0;
40 this->m_bitmapPlot = 0;
41 this->m_brushBack = 0;
42
43 this->m_penPlot[0] = 0;
44 this->m_penPlot[1] = 0;
45 this->m_penPlot[2] = 0;
46 this->m_penPlot[3] = 0;
47
48 /* since plotting is based on a LineTo for each new point
49 * we need a starting point (i.e. a "previous" point)
50 * use 0.0 as the default first point.
51 * these are public member variables, and can be changed outside
52 * (after construction). Therefore m_perviousPosition could be set to
53 * a more appropriate value prior to the first call to SetPosition.
54 */
55 this->m_dPreviousPosition[0] = 0.0;
56 this->m_dPreviousPosition[1] = 0.0;
57 this->m_dPreviousPosition[2] = 0.0;
58 this->m_dPreviousPosition[3] = 0.0;
59
60 /* public variable for the number of decimal places on the y axis */
61 this->m_nYDecimals = 3;
62
63 /* set some initial values for the scaling until "SetRange" is called.
64 * these are protected variables and must be set with SetRange
65 * in order to ensure that m_dRange is updated accordingly
66 */
67 /* m_dLowerLimit = -10.0; */
68 /* m_dUpperLimit = 10.0; */
69 this->m_dLowerLimit = 0.0;
70 this->m_dUpperLimit = 100.0;
71 this->m_dRange = this->m_dUpperLimit - this->m_dLowerLimit; /* protected member variable */
72
73 /* m_nShiftPixels determines how much the plot shifts (in terms of pixels) */
74 /* with the addition of a new data point */
75 this->m_nShiftPixels = 4;
76 this->m_nHalfShiftPixels = this->m_nShiftPixels/2; /* protected */
77 this->m_nPlotShiftPixels = this->m_nShiftPixels + this->m_nHalfShiftPixels; /* protected */
78
79 /* background, grid and data colors */
80 /* these are public variables and can be set directly */
81 this->m_crBackColor = RGB( 0, 0, 0); /* see also SetBackgroundColor */
82 this->m_crGridColor = RGB( 0, 128, 64); /* see also SetGridColor */
83 this->m_crPlotColor[0] = RGB(255, 255, 255); /* see also SetPlotColor */
84 this->m_crPlotColor[1] = RGB(100, 255, 255); /* see also SetPlotColor */
85 this->m_crPlotColor[2] = RGB(255, 100, 255); /* see also SetPlotColor */
86 this->m_crPlotColor[3] = RGB(255, 255, 100); /* see also SetPlotColor */
87
88 /* protected variables */
89 for (i = 0; i < MAX_PLOTS; i++)
90 {
91 this->m_penPlot[i] = CreatePen(PS_SOLID, 0, this->m_crPlotColor[i]);
92 }
93 this->m_brushBack = CreateSolidBrush(this->m_crBackColor);
94
95 /* public member variables, can be set directly */
96 strcpy(this->m_strXUnitsString, "Samples"); /* can also be set with SetXUnits */
97 strcpy(this->m_strYUnitsString, "Y units"); /* can also be set with SetYUnits */
98
99 /* protected bitmaps to restore the memory DC's */
100 this->m_bitmapOldGrid = NULL;
101 this->m_bitmapOldPlot = NULL;
102 }
103
104 void GraphCtrl_Dispose(TGraphCtrl* this)
105 {
106 int plot;
107
108 for (plot = 0; plot < MAX_PLOTS; plot++)
109 DeleteObject(this->m_penPlot[plot]);
110
111 /* just to be picky restore the bitmaps for the two memory dc's */
112 /* (these dc's are being destroyed so there shouldn't be any leaks) */
113
114 if (this->m_bitmapOldGrid != NULL) SelectObject(this->m_dcGrid, this->m_bitmapOldGrid);
115 if (this->m_bitmapOldPlot != NULL) SelectObject(this->m_dcPlot, this->m_bitmapOldPlot);
116 if (this->m_bitmapGrid != NULL) DeleteObject(this->m_bitmapGrid);
117 if (this->m_bitmapPlot != NULL) DeleteObject(this->m_bitmapPlot);
118 if (this->m_dcGrid != NULL) DeleteDC(this->m_dcGrid);
119 if (this->m_dcPlot != NULL) DeleteDC(this->m_dcPlot);
120 if (this->m_brushBack != NULL) DeleteObject(this->m_brushBack);
121 }
122
123 BOOL GraphCtrl_Create(TGraphCtrl* this, HWND hWnd, HWND hParentWnd, UINT nID)
124 {
125 BOOL result = 0;
126
127 GraphCtrl_Init(this);
128 this->m_hParentWnd = hParentWnd;
129 this->m_hWnd = hWnd;
130 GraphCtrl_Resize(this);
131 if (result != 0)
132 GraphCtrl_InvalidateCtrl(this, FALSE);
133 return result;
134 }
135
136 void GraphCtrl_SetRange(TGraphCtrl* this, double dLower, double dUpper, int nDecimalPlaces)
137 {
138 /* ASSERT(dUpper > dLower); */
139 this->m_dLowerLimit = dLower;
140 this->m_dUpperLimit = dUpper;
141 this->m_nYDecimals = nDecimalPlaces;
142 this->m_dRange = this->m_dUpperLimit - this->m_dLowerLimit;
143 this->m_dVerticalFactor = (double)this->m_nPlotHeight / this->m_dRange;
144 /* clear out the existing garbage, re-start with a clean plot */
145 GraphCtrl_InvalidateCtrl(this, FALSE);
146 }
147
148 #if 0
149 void TGraphCtrl::SetXUnits(const char* string)
150 {
151 strncpy(m_strXUnitsString, string, sizeof(m_strXUnitsString) - 1);
152 /* clear out the existing garbage, re-start with a clean plot */
153 InvalidateCtrl();
154 }
155
156 void TGraphCtrl::SetYUnits(const char* string)
157 {
158 strncpy(m_strYUnitsString, string, sizeof(m_strYUnitsString) - 1);
159 /* clear out the existing garbage, re-start with a clean plot */
160 InvalidateCtrl();
161 }
162 #endif
163
164 void GraphCtrl_SetGridColor(TGraphCtrl* this, COLORREF color)
165 {
166 this->m_crGridColor = color;
167 /* clear out the existing garbage, re-start with a clean plot */
168 GraphCtrl_InvalidateCtrl(this, FALSE);
169 }
170
171 void GraphCtrl_SetPlotColor(TGraphCtrl* this, int plot, COLORREF color)
172 {
173 this->m_crPlotColor[plot] = color;
174 DeleteObject(this->m_penPlot[plot]);
175 this->m_penPlot[plot] = CreatePen(PS_SOLID, 0, this->m_crPlotColor[plot]);
176 /* clear out the existing garbage, re-start with a clean plot */
177 GraphCtrl_InvalidateCtrl(this, FALSE);
178 }
179
180 void GraphCtrl_SetBackgroundColor(TGraphCtrl* this, COLORREF color)
181 {
182 this->m_crBackColor = color;
183 DeleteObject(this->m_brushBack);
184 this->m_brushBack = CreateSolidBrush(this->m_crBackColor);
185 /* clear out the existing garbage, re-start with a clean plot */
186 GraphCtrl_InvalidateCtrl(this, FALSE);
187 }
188
189 void GraphCtrl_InvalidateCtrl(TGraphCtrl* this, BOOL bResize)
190 {
191 /* There is a lot of drawing going on here - particularly in terms of */
192 /* drawing the grid. Don't panic, this is all being drawn (only once) */
193 /* to a bitmap. The result is then BitBlt'd to the control whenever needed. */
194 int i;
195 int nCharacters;
196 //int nTopGridPix, nMidGridPix, nBottomGridPix;
197
198 HPEN oldPen;
199 HPEN solidPen = CreatePen(PS_SOLID, 0, this->m_crGridColor);
200 /* HFONT axisFont, yUnitFont, oldFont; */
201 /* char strTemp[50]; */
202
203 /* in case we haven't established the memory dc's */
204 /* CClientDC dc(this); */
205 HDC dc = GetDC(this->m_hParentWnd);
206
207 /* if we don't have one yet, set up a memory dc for the grid */
208 if (this->m_dcGrid == NULL)
209 {
210 this->m_dcGrid = CreateCompatibleDC(dc);
211 this->m_bitmapGrid = CreateCompatibleBitmap(dc, this->m_nClientWidth, this->m_nClientHeight);
212 this->m_bitmapOldGrid = (HBITMAP)SelectObject(this->m_dcGrid, this->m_bitmapGrid);
213 }
214 else if(bResize)
215 {
216 // the size of the drawing area has changed
217 // so create a new bitmap of the appropriate size
218 if(this->m_bitmapGrid != NULL)
219 {
220 this->m_bitmapGrid = (HBITMAP)SelectObject(this->m_dcGrid, this->m_bitmapOldGrid);
221 DeleteObject(this->m_bitmapGrid);
222 this->m_bitmapGrid = CreateCompatibleBitmap(dc, this->m_nClientWidth, this->m_nClientHeight);
223 SelectObject(this->m_dcGrid, this->m_bitmapGrid);
224 }
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
255 /* draw the horizontal axis */
256 for (i = this->m_rectPlot.top; i < this->m_rectPlot.bottom; i += 12)
257 {
258 MoveToEx(this->m_dcGrid, this->m_rectPlot.left, this->m_rectPlot.top + i, NULL);
259 LineTo(this->m_dcGrid, this->m_rectPlot.right, this->m_rectPlot.top + i);
260 }
261
262 /* draw the vertical axis */
263 for (i = this->m_rectPlot.left; i < this->m_rectPlot.right; i += 12)
264 {
265 MoveToEx(this->m_dcGrid, this->m_rectPlot.left + i, this->m_rectPlot.bottom, NULL);
266 LineTo(this->m_dcGrid, this->m_rectPlot.left + i, this->m_rectPlot.top);
267 }
268
269 SelectObject(this->m_dcGrid, oldPen);
270 DeleteObject(solidPen);
271
272 #if 0
273 /* create some fonts (horizontal and vertical) */
274 /* use a height of 14 pixels and 300 weight */
275 /* (these may need to be adjusted depending on the display) */
276 axisFont = CreateFont (14, 0, 0, 0, 300,
277 FALSE, FALSE, 0, ANSI_CHARSET,
278 OUT_DEFAULT_PRECIS,
279 CLIP_DEFAULT_PRECIS,
280 DEFAULT_QUALITY,
281 DEFAULT_PITCH|FF_SWISS, "Arial");
282 yUnitFont = CreateFont (14, 0, 900, 0, 300,
283 FALSE, FALSE, 0, ANSI_CHARSET,
284 OUT_DEFAULT_PRECIS,
285 CLIP_DEFAULT_PRECIS,
286 DEFAULT_QUALITY,
287 DEFAULT_PITCH|FF_SWISS, "Arial");
288
289 /* grab the horizontal font */
290 oldFont = (HFONT)SelectObject(m_dcGrid, axisFont);
291
292 /* y max */
293 SetTextColor(m_dcGrid, m_crGridColor);
294 SetTextAlign(m_dcGrid, TA_RIGHT|TA_TOP);
295 sprintf(strTemp, "%.*lf", m_nYDecimals, m_dUpperLimit);
296 TextOut(m_dcGrid, m_rectPlot.left-4, m_rectPlot.top, strTemp, wcslen(strTemp));
297
298 /* y min */
299 SetTextAlign(m_dcGrid, TA_RIGHT|TA_BASELINE);
300 sprintf(strTemp, "%.*lf", m_nYDecimals, m_dLowerLimit);
301 TextOut(m_dcGrid, m_rectPlot.left-4, m_rectPlot.bottom, strTemp, wcslen(strTemp));
302
303 /* x min */
304 SetTextAlign(m_dcGrid, TA_LEFT|TA_TOP);
305 TextOut(m_dcGrid, m_rectPlot.left, m_rectPlot.bottom+4, "0", 1);
306
307 /* x max */
308 SetTextAlign(m_dcGrid, TA_RIGHT|TA_TOP);
309 sprintf(strTemp, "%d", m_nPlotWidth/m_nShiftPixels);
310 TextOut(m_dcGrid, m_rectPlot.right, m_rectPlot.bottom+4, strTemp, wcslen(strTemp));
311
312 /* x units */
313 SetTextAlign(m_dcGrid, TA_CENTER|TA_TOP);
314 TextOut(m_dcGrid, (m_rectPlot.left+m_rectPlot.right)/2,
315 m_rectPlot.bottom+4, m_strXUnitsString, wcslen(m_strXUnitsString));
316
317 /* restore the font */
318 SelectObject(m_dcGrid, oldFont);
319
320 /* y units */
321 oldFont = (HFONT)SelectObject(m_dcGrid, yUnitFont);
322 SetTextAlign(m_dcGrid, TA_CENTER|TA_BASELINE);
323 TextOut(m_dcGrid, (m_rectClient.left+m_rectPlot.left)/2,
324 (m_rectPlot.bottom+m_rectPlot.top)/2, m_strYUnitsString, wcslen(m_strYUnitsString));
325 SelectObject(m_dcGrid, oldFont);
326 #endif
327 /* at this point we are done filling the grid bitmap, */
328 /* no more drawing to this bitmap is needed until the settings are changed */
329
330 /* if we don't have one yet, set up a memory dc for the plot */
331 if (this->m_dcPlot == NULL)
332 {
333 this->m_dcPlot = CreateCompatibleDC(dc);
334 this->m_bitmapPlot = CreateCompatibleBitmap(dc, this->m_nClientWidth, this->m_nClientHeight);
335 this->m_bitmapOldPlot = (HBITMAP)SelectObject(this->m_dcPlot, this->m_bitmapPlot);
336 }
337 else if(bResize)
338 {
339 // the size of the drawing area has changed
340 // so create a new bitmap of the appropriate size
341 if(this->m_bitmapPlot != NULL)
342 {
343 this->m_bitmapPlot = (HBITMAP)SelectObject(this->m_dcPlot, this->m_bitmapOldPlot);
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 (excluding 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 segment */
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 CallWindowProcW(OldGraphCtrlWndProc, hWnd, message, wParam, lParam);
640 }