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