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