home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / C / Code Resources / Progress CDEF 1.3 / Progress.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-01-04  |  3.1 KB  |  144 lines  |  [TEXT/CWIE]

  1. /* ----------------------------------------------------------------------
  2.  
  3.     Progress CDEF
  4.     version 1.3
  5.     
  6.     Written by: Paul Celestin
  7.     
  8.     Copyright © 1993-1995 Celestin Company, Inc.
  9.     
  10.     This CDEF displays a very simple progress thermometer.
  11.     
  12.     930927 - 1.0.0 - initial release
  13.     931012 - 1.0.1 - bug fixes
  14.     940320 - 1.0.2 - more bug fixes
  15.     951215 - 1.3.0 - updated for CW7
  16.  
  17. ---------------------------------------------------------------------- */
  18.  
  19. /* ----------------------------------------------------------------------
  20. prototypes
  21. ---------------------------------------------------------------------- */
  22. pascal long main(short, ControlHandle, short, long);
  23. void drawIt(ControlHandle, short);
  24.  
  25.  
  26. /* ----------------------------------------------------------------------
  27. main
  28. ---------------------------------------------------------------------- */
  29. pascal long main(short variation, ControlHandle theControl, short message, long param)
  30. {
  31.     long    returnValue = 0L;
  32.     char    state = HGetState((Handle)theControl);
  33.  
  34.     switch(message)
  35.     {
  36.         case drawCntl:
  37.             drawIt(theControl,variation);
  38.         case testCntl:
  39.             break;
  40.         case calcCRgns:
  41.             break;
  42.           case initCntl:
  43.               break;
  44.         case dispCntl:
  45.             break;
  46.         case posCntl:
  47.             break;
  48.         case thumbCntl:
  49.             break;
  50.         case dragCntl:
  51.             break;
  52.         case autoTrack:
  53.             break;
  54.         case calcCntlRgn:
  55.             break;
  56.         case calcThumbRgn:
  57.             break;
  58.         default:
  59.             break;
  60.     }
  61.  
  62.     HSetState((Handle)theControl,state);
  63.  
  64.     return(returnValue);                /* tell them what happened */
  65. }
  66.  
  67.  
  68. /* ----------------------------------------------------------------------
  69. drawIt - here is where we actually draw the control
  70. ---------------------------------------------------------------------- */
  71. void drawIt(ControlHandle control, short variation)
  72.  
  73. {
  74.     Rect             myRect;
  75.     PenState        oldPenState;
  76.     int                myValue = GetCtlValue(control),
  77.                     myMax = GetCtlMax(control),
  78.                     myMin = GetCtlMin(control),
  79.                     myColor,
  80.                     width = 0,
  81.                     range = 100;
  82.  
  83.     if (!(*control)->contrlVis)                /* if not visible, do nothing */
  84.         return;
  85.  
  86.     GetPenState(&oldPenState);                /* save off current environment */
  87.  
  88.     myRect = (*control)->contrlRect;        /* define our control rect */
  89.     
  90.     PenNormal();                            /* make pen normal */
  91.     
  92.     FrameRect(&myRect);                        /* draw border around the control */
  93.     InsetRect(&myRect,1,1);
  94.  
  95.     ForeColor(whiteColor);
  96.     BackColor(whiteColor);
  97.     PaintRect(&myRect);
  98.  
  99.     width = myRect.right - myRect.left;        /* width in pixels of the control */
  100.     range = myMax - myMin;
  101.     
  102.     if (range < 10) range = 10;                /* to deal with screwy ranges */
  103.     
  104.     myRect.right = myRect.left + (myValue * width) / range;
  105.     
  106.     switch (GetCRefCon(control))
  107.     {
  108.         case 1:
  109.             myColor = redColor;
  110.             break;
  111.         case 2:
  112.             myColor = greenColor;
  113.             break;
  114.         case 3:
  115.             myColor = blueColor;
  116.             break;
  117.         case 4:
  118.             myColor = cyanColor;
  119.             break;
  120.         case 5:
  121.             myColor = magentaColor;
  122.             break;
  123.         case 6:
  124.             myColor = yellowColor;
  125.             break;
  126.         case 7:
  127.             myColor = whiteColor;
  128.             break;
  129.         default:
  130.             myColor = blackColor;
  131.             break;
  132.     }
  133.     
  134.     ForeColor(myColor);
  135.     BackColor(myColor);
  136.     PaintRect(&myRect);
  137.  
  138.     ForeColor(blackColor);
  139.     BackColor(whiteColor);
  140.     SetPenState(&oldPenState);                /* restore the original environment */
  141.     
  142.     return;                                    /* we are done drawing */
  143. }
  144.