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