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