home *** CD-ROM | disk | FTP | other *** search
/ Executor 2.0 / executorv2.0.iso / pc / dos / extra / source / browser / browser.hqx / Browser / initdirs.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-11-05  |  4.4 KB  |  176 lines

  1. #include "go.h"
  2. #include "display.h"
  3. #include <string.h>
  4.  
  5. #include "initdirs.proto.h"
  6. #include "initicons.proto.h"
  7. #include "init.proto.h"
  8. #include "misc.proto.h"
  9. #include "window.proto.h"
  10. #include "windlist.h"
  11. #include "inithotband.proto.h"
  12. #include "mouse.proto.h"
  13.  
  14. ControlHandle
  15. addtolist (WindowPeek wp, Str255 s, long dirid, short vrefnum)
  16. {
  17.   ControlHandle c;
  18.   opendirinfo **infoh;
  19.  
  20.   infoh = (opendirinfo **) wp->refCon;
  21.   c = getnewiconcontrol ((WindowPtr) wp, (*infoh)->path, dirid, vrefnum, s,
  22.                 (*infoh)->view);
  23.   (**(*infoh)->items)[(*infoh)->numitems++] = c;
  24.   return c;
  25. }
  26.  
  27. static Handle
  28. icon_path (ControlHandle c)
  29. {
  30.   return (*(item **)(*c)->contrlData)->path;
  31. }
  32.  
  33. static void
  34. str_assign (char *destp, char *srcp, long length)
  35. {
  36.   memcpy (destp, srcp, length);
  37.   destp[length] = 0;
  38. }
  39.  
  40. void
  41. update_title (ControlHandle c, Str255 s)
  42. {
  43.   long old_path_length, new_path_length, expected_size;
  44.   Handle old_path, new_path;
  45.   WindowPeek wp;
  46.   unsigned char state;
  47.   long length;
  48.   
  49.   new_path = old_path = icon_path (c);
  50.   HandToHand (&old_path);
  51.   HandToHand (&new_path);
  52.   
  53.   if (is_volume (c))
  54.     {
  55.       old_path_length = strlen (*old_path) + 1;
  56.       new_path_length = s[0];
  57.       SetHandleSize (new_path, new_path_length + 1);
  58.       str_assign (*new_path, (char *) s + 1, new_path_length);
  59.       ++new_path_length;
  60.       SetHandleSize (icon_path (c), new_path_length);
  61.       memcpy (*(icon_path (c)), *new_path, new_path_length);
  62.       expected_size = new_path_length;
  63.       --old_path_length;
  64.       --new_path_length;
  65.     }
  66.   else
  67.     {
  68.       length = strlen (*old_path) + 1;
  69.       (*old_path)[length - 1] = (*new_path)[length - 1] = ':';
  70.       SetHandleSize (old_path, length);
  71.       SetHandleSize (new_path, length);
  72.       PtrAndHand ((*c)->contrlTitle + 1, old_path, (*c)->contrlTitle[0]);
  73.       PtrAndHand (s + 1, new_path, s[0]);
  74.       old_path_length = length + (*c)->contrlTitle[0];
  75.       new_path_length = length + s[0];
  76.       expected_size = new_path_length + 1;
  77.     }
  78.   
  79.   HLock (old_path);
  80.   HLock (new_path);
  81.   for (wp = WindowList; wp != 0; wp = wp->nextWindow)
  82.     {
  83.       if (browser_window_p ((WindowPtr) wp))
  84.         {
  85.           opendirinfo **opendir_hand;
  86.           
  87.           opendir_hand = (opendirinfo **) wp->refCon;
  88.       state = HGetState ((Handle) opendir_hand);
  89.       HLock ((Handle) opendir_hand);
  90.       if (Munger ((*opendir_hand)->path, 0, *old_path, old_path_length, 0, 0) == 0)
  91.         {
  92.           Munger ((*opendir_hand)->path, 0, *old_path, old_path_length,
  93.                   *new_path, new_path_length);
  94.           if (GetHandleSize ((*opendir_hand)->path) == expected_size)
  95.             SetWTitle ((WindowPtr) wp, s);
  96.         }
  97.       HSetState ((Handle) opendir_hand, state);
  98.      }
  99.     }
  100.     DisposHandle (old_path);
  101.     DisposHandle (new_path);
  102. }
  103.  
  104. void
  105. updatemove (WindowPeek wp, Str255 sp, long dirid, short vrefnum)
  106. {
  107.   ControlHandle c;
  108.   Str255 s;
  109.  
  110.   mystr255copy (s, sp);
  111.   if (s[s[0]] == ':')
  112.     --s[0];
  113.  
  114.   c = addtolist (wp, s, dirid, vrefnum);
  115.   setoneicon (c);
  116.   ShowControl (c);
  117.   straightenwindow ((WindowPtr) wp);
  118. }
  119.  
  120. void
  121. removefromlist (WindowPeek wp, Str255 s, long dirid, short vrefnum)
  122. {
  123.   ControlHandle c, *cp;
  124.   short i, n;
  125.  
  126.   cp = **(*(opendirinfo **) wp->refCon)->items;
  127.   for (i = 0; i < (*(opendirinfo **) wp->refCon)->numitems
  128.       && RelString ((*cp[i])->contrlTitle, s, false, false); i++)
  129.     ;
  130.   if (i < (*(opendirinfo **) wp->refCon)->numitems)
  131.     {
  132.       c = cp[i];
  133.       n = --(*(opendirinfo **) wp->refCon)->numitems;
  134.       memmove(cp + i, cp + i + 1, (n - i) * sizeof(cp[0]) );
  135.  
  136. /* NOTE: I (ctm) have no idea why we need FALSE here.  If we use True, bad things will happen
  137.    when we rename folders and then open them up.  I'm very suspicions of the entire way the path
  138.    field of an Icon is manipulated, but I don't have time to overhaul this aspect of Loser
  139.    now. */
  140.  
  141.       Dispose_Icon (c, FALSE);
  142.     }
  143. }
  144.  
  145. void
  146. initopendirs (FILE * f)
  147. {
  148.   CInfoPBRec cpb;
  149.   CWindowPeek wp;
  150.   short c;
  151.   OSErr e;
  152.   char **path;
  153.   Rect r;
  154.   short volume;
  155.  
  156.   while ((c = getc (f)) && (c != EOF))
  157.     {
  158.       ungetc (c, f);
  159.       e = getonefileinfo (f, &cpb, &path, &volume);
  160.       fscanf (f, "%d %d %d %d\n", &r.left, &r.top, &r.right, &r.bottom);
  161.       if (!e && (cpb.hFileInfo.ioFlAttrib & DIRBIT))
  162.     {
  163.       wp = (CWindowPeek) createdirwindow (&cpb, &r, path, volume);
  164.     }
  165.       for (wp = (CWindowPeek) WindowList; wp != 0; wp = wp->nextWindow)
  166.     {
  167.       if (browser_window_p ((WindowPtr) wp))
  168.         {
  169.           setwindowicons (wp);
  170.           ShowWindow ((WindowPtr) wp);
  171.           flush_screen_writes ();
  172.         }
  173.     }
  174.     }
  175. }
  176.