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