home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Code Resources / Progress CDEFs 1.3 / Progress Tester.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-03-16  |  3.2 KB  |  154 lines  |  [TEXT/KAHL]

  1. /*
  2.  * Progress Tester.c
  3.  *
  4.  * By Eddy J. Gurney
  5.  *
  6.  * Simple program to test my Progress CDEF's
  7.  *
  8.  */
  9.  
  10. void ToolBoxInit()
  11. {
  12.     InitGraf(&thePort);
  13.     InitFonts();
  14.     FlushEvents(everyEvent, 0);
  15.     InitWindows();
  16.     InitMenus();
  17.     TEInit();
  18.     InitDialogs(nil);
  19.     MaxApplZone();
  20.     InitCursor();
  21.     
  22.     SetDAFont(applFont);
  23. }
  24.  
  25. void DoDialogUpdate(DialogPtr theDialog)
  26. {
  27.     GrafPtr    savePort;
  28.     
  29.     GetPort(&savePort);
  30.     SetPort(theDialog);
  31.     
  32.     BeginUpdate(theDialog);
  33.     UpdtDialog(theDialog, theDialog->visRgn);
  34.     EndUpdate(theDialog);
  35.     SetPort(savePort);
  36. }
  37.  
  38. void DoDialogActivate(DialogPtr theDialog, Boolean active)
  39. {
  40.     SetPort(theDialog);
  41. }
  42.  
  43. pascal Boolean DialogFilter(DialogPtr theDialog, EventRecord *theEvent, short *theItem)
  44. {
  45.     short        iType;
  46.     Handle        iHandle;
  47.     Rect            iRect;
  48.     char            theChar;
  49.     Boolean        result = FALSE;
  50.     WindowPtr    theWindow;
  51.     long            endTicks;
  52.     static long        nextUpdate = 0;
  53.  
  54.     theWindow = (WindowPtr)(theEvent->message);
  55.     switch (theEvent->what) {
  56.         case updateEvt:
  57.             if (theWindow == theDialog) {
  58.                 DoDialogUpdate(theDialog);
  59.                 result = TRUE;
  60.                 *theItem = 0;
  61.             }
  62.             break;
  63.         case activateEvt:
  64.             if (theWindow == theDialog) {
  65.                 DoDialogActivate(theDialog, (theEvent->modifiers & activeFlag) != 0);
  66.                 *theItem = 0;
  67.             }
  68.             break;
  69.         case keyDown:
  70.         case autoKey:
  71.             theChar = theEvent->message & charCodeMask;
  72.             if (theChar == 0x0d || theChar == 0x03) {    /* Return/Enter key? */
  73.                 GetDItem(theDialog, ok, &iType, &iHandle, &iRect);
  74.                 HiliteControl((ControlHandle)iHandle, 1);
  75.                 Delay(8, &endTicks);
  76.                 HiliteControl((ControlHandle)iHandle, 0);
  77.                 *theItem = ok;
  78.                 return TRUE;
  79.             }
  80.             break;
  81.         case nullEvent:
  82.             if (TickCount() > nextUpdate) {
  83.                 short value;
  84.  
  85.                 /* Update the progress bar */
  86.                 GetDItem(theDialog, 2, &iType, &iHandle, &iRect);
  87.                 if ((value = GetCtlValue((ControlHandle)iHandle)) >= GetCtlMax((ControlHandle)iHandle))
  88.                     value = GetCtlMin((ControlHandle)iHandle);
  89.                 else
  90.                     value++;
  91.                 SetCtlValue((ControlHandle)iHandle, value);
  92.                 
  93.                 /* Update the progress arc */
  94.                 GetDItem(theDialog, 3, &iType, &iHandle, &iRect);
  95.                 if ((value = GetCtlValue((ControlHandle)iHandle)) >= GetCtlMax((ControlHandle)iHandle))
  96.                     value = GetCtlMin((ControlHandle)iHandle);
  97.                 else
  98.                     value++;
  99.                 SetCtlValue((ControlHandle)iHandle, value);
  100.                 
  101.                 /* Item 4 is the thermometer PICT */
  102.                 
  103.                 /* Update the vertical progress bar */
  104.                 GetDItem(theDialog, 5, &iType, &iHandle, &iRect);
  105.                 if ((value = GetCtlValue((ControlHandle)iHandle)) >= GetCtlMax((ControlHandle)iHandle))
  106.                     value = GetCtlMin((ControlHandle)iHandle);
  107.                 else
  108.                     value++;
  109.                 SetCtlValue((ControlHandle)iHandle, value);
  110.  
  111.                 nextUpdate = TickCount() + 3;            
  112.             }
  113.             break;
  114.     }
  115.     return result;
  116. }
  117.  
  118. main()
  119. {
  120.     GrafPtr        savePort;
  121.     DialogPtr        theDialog;
  122.     short        itemHit, iType;
  123.     Handle        iHandle, rsrcHandle;
  124.     Boolean        dialogDone = FALSE;
  125.     Rect            iRect;
  126.     Str255        theString;
  127.     long            theValue;
  128.     
  129.     ToolBoxInit();
  130.     
  131.     if ((theDialog = GetNewDialog(400, nil, (WindowPtr)-1)) == nil) {
  132.         SysBeep(1);
  133.         ExitToShell();
  134.     }
  135.     
  136.     GetPort(&savePort);    
  137.     SelectWindow(theDialog);
  138.       SetPort(theDialog);
  139.  
  140.     ShowWindow(theDialog);
  141.  
  142.     while (!dialogDone) {
  143.         ModalDialog(DialogFilter, &itemHit);
  144.         switch (itemHit) {
  145.             case ok:
  146.                 dialogDone = TRUE;
  147.                 break;
  148.         }
  149.     }
  150.     DisposDialog(theDialog);
  151.       SetPort(savePort);
  152.       ExitToShell();
  153. }
  154.