home *** CD-ROM | disk | FTP | other *** search
/ ftp.mactech.com 2010 / ftp.mactech.com.tar / ftp.mactech.com / online / source / c / compilers / Tickle-4.0.sit.hqx / Tickle-4.0 / src / progress.c < prev    next >
Text File  |  1993-11-18  |  6KB  |  284 lines

  1.  
  2. /*
  3. ** This source code was written by Tim Endres
  4. ** Email: time@ice.com.
  5. ** USMail: 8840 Main Street, Whitmore Lake, MI  48189
  6. **
  7. ** Some portions of this application utilize sources
  8. ** that are copyrighted by ICE Engineering, Inc., and
  9. ** ICE Engineering retains all rights to those sources.
  10. **
  11. ** Neither ICE Engineering, Inc., nor Tim Endres, 
  12. ** warrants this source code for any reason, and neither
  13. ** party assumes any responsbility for the use of these
  14. ** sources, libraries, or applications. The user of these
  15. ** sources and binaries assumes all responsbilities for
  16. ** any resulting consequences.
  17. */
  18.  
  19. #pragma segment Progress
  20.  
  21. #include "tickle.h"
  22. #include <OSEvents.h>
  23.  
  24. typedef void (*PFV)();
  25.  
  26. WindowPtr        progress_window = NULL;
  27. PFV                progress_string_func = (PFV)0;
  28. int                progress_pos, progress_start, progress_end;
  29. short            progress_active = 0, progress_right = 0;
  30. unsigned long    progress_tick = 0;
  31. PixPatHandle    progress_backpat = NULL;
  32. PixPatHandle    progress_progpat = NULL;
  33.  
  34. void
  35. SPPercentCompleteProc(message, start, end, pos)
  36.     char    *message;
  37.     int        start;
  38.     int        end;
  39.     int        pos;
  40.     {
  41.     sprintf( message, "Completed %02d%%...",
  42.              ( ((pos - start) * 100) / (end - start) ) );
  43.     }
  44.  
  45. void
  46. SProgressCounting(message, start, end, pos)
  47.     char    *message;
  48.     int        start;
  49.     int        end;
  50.     int        pos;
  51.     {
  52. #pragma unused (end)
  53.  
  54.     sprintf(message, "Counting %d files...", (pos - start));
  55.     }
  56.  
  57. void
  58. SProgressCopyFiles(message, start, end, pos)
  59.     char    *message;
  60.     int        start;
  61.     int        end;
  62.     int        pos;
  63.     {
  64. #pragma unused (pos)
  65.  
  66.     sprintf(message, "Copied %d of %d files...",
  67.             (progress_pos - progress_start), (end - start));
  68.     }
  69.  
  70. StartProgressWindow(title, start, end, pos, string_func)
  71.     char    *title;    /* Pascal */
  72.     int        start;
  73.     int        end;
  74.     PFV        string_func;
  75.     {
  76.     Rect    myrect;
  77.     int        progressWProc();
  78.  
  79.     if (progress_window == (WindowPtr)0)
  80.         {
  81.         SetRect(&myrect, 25, 50, 275, 85);
  82.         if (theEnviron.hasColorQD)
  83.             {
  84.             progress_window = NewCWindow(NULL, &myrect, title, true,
  85.                                         noGrowDocProc, inFront, false, (long)progressWProc);
  86.             progress_backpat = GetPixPat(6979);
  87.             progress_progpat = GetPixPat(6984);
  88.             }
  89.         else
  90.             {
  91.             progress_window = NewWindow(NULL, &myrect, title, true,
  92.                                         noGrowDocProc, inFront, false, (long)progressWProc);
  93.             progress_backpat = (PixPatHandle)0;
  94.             progress_progpat = (PixPatHandle)0;
  95.             }
  96.             
  97.         if (progress_window != (WindowPtr)0)
  98.             ((WindowPeek) progress_window)->windowKind = progressWKind;
  99.         
  100.         }
  101.  
  102.     progress_start = start;
  103.     progress_end = end;
  104.     progress_pos = pos;
  105.  
  106.     progress_right = 1;
  107.     progress_tick = TickCount() - 1;
  108.     
  109.     progress_string_func = string_func;
  110.     }
  111.  
  112. UpdateProgress(pos)
  113.     int        pos;
  114.     {
  115.     Rect    myrect;
  116.     int        need_inval = 0;
  117.  
  118.     if (progress_window != NULL)
  119.         {
  120.         if (progress_end == -1)
  121.             {
  122.             if (TickCount() > progress_tick)
  123.                 need_inval = 1;
  124.             }
  125.         else if (progress_pos != pos)
  126.             {
  127.             if (TickCount() > progress_tick)
  128.                 need_inval = 1;
  129.             }
  130.         
  131.         if (pos == -1)
  132.             {
  133.             progress_pos = progress_end;
  134.             need_inval = 1;
  135.             }
  136.         else
  137.             {
  138.             progress_pos = pos;
  139.             }
  140.         
  141.         if (need_inval)
  142.             {
  143.             focus(progress_window);
  144.             
  145.             myrect = progress_window->portRect;
  146.             InsetRect(&myrect, 4, 4);
  147.             myrect.top = myrect.bottom - 12;
  148.             InsetRect(&myrect, 1, 1);
  149.             InvalRect(&myrect);
  150.             
  151.             myrect = progress_window->portRect;
  152.             myrect.bottom = myrect.top + 20;
  153.             InsetRect(&myrect, 3, 3);
  154.             InvalRect(&myrect);
  155.             
  156.             progressW_update(progress_window);
  157.             
  158.             unfocus();
  159.             }
  160.         }
  161.     }
  162.  
  163. StopProgressWindow()
  164.     {
  165.     int        progressWProc();
  166.  
  167.     if (progress_window != NULL)
  168.         {
  169.         DisposeWindow(progress_window);
  170.         progress_window = (WindowPtr)0;
  171.         }
  172.     }
  173.  
  174. progressWProc(myWindow, myEvent, wAction)
  175.     WindowPtr        myWindow;
  176.     EventRecord        *myEvent;
  177.     int                wAction;
  178.     {
  179. #pragma unused (myEvent)
  180.  
  181.     switch (wAction) {
  182.         case wContent:
  183.             SysBeep(0);    /* Need cancel button... */
  184.             break;
  185.         case wActivate:
  186.             progressW_activate(myWindow, (myEvent->modifiers & 0x00000001) != 0);
  187.             break;
  188.         case wUpdate:
  189.             progressW_update(myWindow);
  190.             break;
  191.         case wClose:
  192.             break;
  193.         case wKeyDown:
  194.             SysBeep(0);    /* Need cancel button... */
  195.             break;
  196.         }
  197.     }
  198.     
  199. progressW_update(myWindow)
  200.     WindowPtr    myWindow;
  201.     {
  202.     double    percent;
  203.     Rect    myrect;
  204.     char    message[256];
  205.  
  206.     focus(myWindow);
  207.     BeginUpdate(myWindow);
  208.     
  209.     myrect = myWindow->portRect;
  210.     EraseRect(&myrect);
  211.     InsetRect(&myrect, 1, 1);
  212.     FrameRect(&myrect);
  213.     
  214.     myrect = myWindow->portRect;
  215.     InsetRect(&myrect, 4, 4);
  216.     myrect.top = myrect.bottom - 12;
  217.     
  218.     FrameRect(&myrect);
  219.     InsetRect(&myrect, 1, 1);
  220.     
  221.     if (theEnviron.hasColorQD && progress_backpat != NULL)
  222.         FillCRect(&myrect, progress_backpat);
  223.  
  224.     if (progress_end != -1)
  225.         {
  226.         percent = ((double) progress_pos) /
  227.                     ( (double) progress_end - (double) progress_start );
  228.         
  229.         myrect.right = myrect.left + (int)( percent * (double)(myrect.right - myrect.left) );
  230.         progress_tick = TickCount() + 20;
  231.         }
  232.     else if (TickCount() > progress_tick)
  233.         {
  234.         if (progress_right)
  235.             {
  236.             myrect.right = myrect.left + ( (myrect.right - myrect.left) >> 1 );
  237.             progress_right = 0;
  238.             }
  239.         else
  240.             {
  241.             myrect.left = myrect.right - ( (myrect.right - myrect.left) >> 1 );
  242.             progress_right = 1;
  243.             }
  244.         progress_tick = TickCount() + 45;
  245.         }
  246.     else
  247.         {
  248.         myrect.right = myrect.left;
  249.         }
  250.     
  251.     if (theEnviron.hasColorQD && progress_backpat != NULL)
  252.         FillCRect(&myrect, progress_progpat);
  253.     else
  254.         FillRect(&myrect, qd.black);
  255.     
  256.     MoveTo(myWindow->portRect.left + 5, myWindow->portRect.top + 15);
  257.     if (progress_string_func != (PFV)0)
  258.         {
  259.         (progress_string_func) (message, progress_start, progress_end, progress_pos);
  260.         }
  261.     else
  262.         {
  263.         sprintf(message, "Completed %d of %d...",
  264.                     progress_pos - progress_start, progress_end - progress_start);
  265.         }
  266.     c2pstr(message);
  267.     
  268.     TextFont(systemFont); TextSize(12);
  269.     DrawString(message);
  270.  
  271.     EndUpdate(myWindow);
  272.     unfocus();
  273.     }
  274.  
  275. progressW_activate(myWindow, actflag)
  276.     WindowPtr    myWindow;
  277.     long        actflag;
  278.     {
  279. #pragma unused (myWindow)
  280.  
  281.     progress_active = actflag;
  282.     }
  283.  
  284.