home *** CD-ROM | disk | FTP | other *** search
/ Executor 2.0 / executorv2.0.iso / pc / dos / extra / source / browser / browser.hqx / Browser / update.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-12-29  |  4.2 KB  |  207 lines

  1. #include "go.h"
  2. #include "display.h"
  3.  
  4. #include "update.proto.h"
  5. #include "inithotband.proto.h"
  6. #include "misc.proto.h"
  7. #include "window.proto.h"
  8.  
  9. #include "windlist.h"
  10.  
  11. void
  12. drawpartialgrowicon (WindowPtr wp, int update_flag)
  13. {
  14.   RgnHandle rgn;
  15.  
  16.   DrawGrowIcon (wp);
  17.   rgn = NewRgn ();
  18.   SetRectRgn (rgn, wp->portRect.left, wp->portRect.bottom - SCROLLBARWIDTH + 1,
  19.           wp->portRect.right - SCROLLBARWIDTH + 1,
  20.           wp->portRect.bottom - SCROLLBARWIDTH + 3);
  21.   EraseRgn (rgn);
  22.   if (update_flag)
  23.     UpdtControl (wp, rgn);
  24.   DisposeRgn (rgn);
  25. }
  26.  
  27. void
  28. doactivate (EventRecord * ev)
  29. {
  30.   WindowPtr wp;
  31.  
  32.   wp = (WindowPtr) ev->message;
  33.   if (ev->modifiers & activeFlag)
  34.     {
  35.       SetPort (wp);
  36.     }
  37.   if (wp == g_hotband)
  38.     {
  39. /* TODO: hilite the controls */
  40.     }
  41.   else
  42.     {
  43.       drawpartialgrowicon (wp, true);
  44.       if (ev->modifiers & activeFlag)
  45.     ShowControl ((*(opendirinfo **) ((WindowPeek) wp)->refCon)->sbar);
  46.       else
  47.     HideControl ((*(opendirinfo **) ((WindowPeek) wp)->refCon)->sbar);
  48.     }
  49. }
  50.  
  51. void
  52. doupdate (EventRecord *ev)
  53. {
  54.   GrafPtr saveport;
  55.   WindowPtr wp;
  56.  
  57.   wp = (WindowPtr) ev->message;
  58.  
  59.   GetPort (&saveport);
  60.   SetPort (wp);
  61.   BeginUpdate (wp);
  62.   if (wp == g_hotband)
  63.     {
  64.       if (((WindowPeek) wp)->refCon & WIPEBIT)
  65.     {
  66.       EraseRect (&wp->portRect);
  67.       ((WindowPeek) wp)->refCon ^= WIPEBIT;
  68.     }
  69.     }
  70.   else
  71.     {
  72.       EraseRect (&wp->portRect);
  73.       drawpartialgrowicon (wp, true);
  74.     }
  75.   UpdtControl (wp, wp->visRgn);
  76.   EndUpdate (wp);
  77.   SetPort (saveport);
  78. }
  79.  
  80. static boolean_t
  81. exists (short vref, long dirid)
  82. {
  83.   CInfoPBRec cpb;
  84.   OSErr err;
  85.   Str255 file_name;
  86.   
  87.   cpb.hFileInfo.ioVRefNum = vref;
  88.   cpb.hFileInfo.ioDirID = dirid;
  89.   cpb.hFileInfo.ioFDirIndex = -1;
  90.   cpb.hFileInfo.ioNamePtr = file_name;
  91.   err = PBGetCatInfo (&cpb, false);
  92.   
  93.   return err == noErr;
  94. }
  95.  
  96. void
  97. close_windows_no_longer_present (void)
  98. {
  99.   WindowPeek wp, next;
  100.  
  101. #ifdef THINK_C
  102.   for (wp = WindowList; wp != 0; wp = next)
  103. #else
  104.   for (wp = LMGetWindowList (); wp != 0; wp = next)
  105. #endif
  106.     {
  107.       next = wp->nextWindow;
  108.       if (browser_window_p ((WindowPtr) wp))
  109.         {
  110.           if (!exists ((*(opendirinfo **) wp->refCon)->vrefnum,
  111.                        (*(opendirinfo **) wp->refCon)->iodirid))
  112.             disposedirwindow ((WindowPtr) wp);
  113.         }
  114.     }
  115. }
  116.  
  117. void
  118. changewindow (Str255 s, long dirid, short vrefnum,
  119.           void (*f) (WindowPeek, Str255, long, short))
  120. {
  121.   WindowPeek wp;
  122.  
  123. #ifdef THINK_C
  124.   for (wp = WindowList; wp != 0; wp = wp->nextWindow)
  125. #else
  126.   for (wp = LMGetWindowList (); wp != 0; wp = wp->nextWindow)
  127. #endif
  128.     {
  129.       if (browser_window_p ((WindowPtr) wp) &&
  130.       (*(opendirinfo **) wp->refCon)->iodirid == dirid &&
  131.       (*(opendirinfo **) wp->refCon)->vrefnum == vrefnum)
  132.     {
  133.       f (wp, s, dirid, vrefnum);
  134.       straightenwindow ((WindowPtr) wp);
  135.     }
  136.     }
  137. }
  138.  
  139. /* TODO: put this in a better file */
  140. short actiontoband (short action);
  141. short
  142. actiontoband (short action)
  143. {
  144.   switch (action)
  145.     {
  146.     case LAUNCH:
  147.       return APPBAND;
  148.       break;
  149.     case OPENDIR:
  150.       return FOLDERBAND;
  151.       break;
  152.     case LAUNCHCREATOR:
  153.       return DOCBAND;
  154.       break;
  155.     case OPENDA:
  156.       return DABAND;
  157.       break;
  158.     case NOACTION:
  159.       return FONTBAND;
  160.       break;
  161.     default:
  162.       return DOCBAND;
  163.       break;
  164.     }
  165. }
  166.  
  167. void
  168. changehot (ControlHandle c, long todir, short tovol)
  169. {
  170.   ControlHandle (**chh)[], c2;
  171.   item **ih;
  172.   short i, j, whichband, fromvol;
  173.   long fromdir;
  174.   bandinfo *p;
  175.   Str255 s;
  176.  
  177.   ih = (item **) (*c)->contrlData;
  178.   fromdir = (*ih)->ioparid;
  179.   fromvol = (*ih)->vrefnum;
  180.   mystr255copy (s, (*c)->contrlTitle);
  181.   whichband = actiontoband ((*ih)->action);
  182.   p = &bands[whichband];
  183.   chh = p->items;
  184.   for (i = 0; i < p->numitems; i++)
  185.     if ((*(item **) (*(**chh)[i])->contrlData)->ioparid == fromdir &&
  186.     (*(item **) (*(**chh)[i])->contrlData)->vrefnum == fromvol &&
  187.     EqualString (s, (*(**chh)[i])->contrlTitle, false, false))
  188.       {
  189.     if (tovol != 0)
  190.       {
  191.         (*(item **) (*(**chh)[i])->contrlData)->ioparid = todir;
  192.         (*(item **) (*(**chh)[i])->contrlData)->vrefnum = tovol;
  193.       }
  194.     else
  195.       {
  196.         c2 = (**chh)[i];
  197.         p->numitems--;
  198.         checkhotbandcontrol ();
  199.         for (j = i; j < p->numitems; j++)
  200.           (**p->items)[j] = (**p->items)[j + 1];
  201.         Dispose_Icon (c2, TRUE);
  202.         if (whichband == g_currentband)
  203.           shiftband (i, -1);
  204.       }
  205.       }
  206. }
  207.