home *** CD-ROM | disk | FTP | other *** search
- #include "go.h"
- #include "display.h"
- #include <string.h>
-
- #include "initdirs.proto.h"
- #include "initicons.proto.h"
- #include "init.proto.h"
- #include "misc.proto.h"
- #include "window.proto.h"
- #include "windlist.h"
- #include "inithotband.proto.h"
- #include "mouse.proto.h"
-
- ControlHandle
- addtolist (WindowPeek wp, Str255 s, long dirid, short vrefnum)
- {
- ControlHandle c;
- opendirinfo **infoh;
-
- infoh = (opendirinfo **) wp->refCon;
- c = getnewiconcontrol ((WindowPtr) wp, (*infoh)->path, dirid, vrefnum, s,
- (*infoh)->view);
- (**(*infoh)->items)[(*infoh)->numitems++] = c;
- return c;
- }
-
- static Handle
- icon_path (ControlHandle c)
- {
- return (*(item **)(*c)->contrlData)->path;
- }
-
- static void
- str_assign (char *destp, char *srcp, long length)
- {
- memcpy (destp, srcp, length);
- destp[length] = 0;
- }
-
- void
- update_title (ControlHandle c, Str255 s)
- {
- long old_path_length, new_path_length, expected_size;
- Handle old_path, new_path;
- WindowPeek wp;
- unsigned char state;
- long length;
-
- new_path = old_path = icon_path (c);
- HandToHand (&old_path);
- HandToHand (&new_path);
-
- if (is_volume (c))
- {
- old_path_length = strlen (*old_path) + 1;
- new_path_length = s[0];
- SetHandleSize (new_path, new_path_length + 1);
- str_assign (*new_path, (char *) s + 1, new_path_length);
- ++new_path_length;
- SetHandleSize (icon_path (c), new_path_length);
- memcpy (*(icon_path (c)), *new_path, new_path_length);
- expected_size = new_path_length;
- --old_path_length;
- --new_path_length;
- }
- else
- {
- length = strlen (*old_path) + 1;
- (*old_path)[length - 1] = (*new_path)[length - 1] = ':';
- SetHandleSize (old_path, length);
- SetHandleSize (new_path, length);
- PtrAndHand ((*c)->contrlTitle + 1, old_path, (*c)->contrlTitle[0]);
- PtrAndHand (s + 1, new_path, s[0]);
- old_path_length = length + (*c)->contrlTitle[0];
- new_path_length = length + s[0];
- expected_size = new_path_length + 1;
- }
-
- HLock (old_path);
- HLock (new_path);
- for (wp = WindowList; wp != 0; wp = wp->nextWindow)
- {
- if (browser_window_p ((WindowPtr) wp))
- {
- opendirinfo **opendir_hand;
-
- opendir_hand = (opendirinfo **) wp->refCon;
- state = HGetState ((Handle) opendir_hand);
- HLock ((Handle) opendir_hand);
- if (Munger ((*opendir_hand)->path, 0, *old_path, old_path_length, 0, 0) == 0)
- {
- Munger ((*opendir_hand)->path, 0, *old_path, old_path_length,
- *new_path, new_path_length);
- if (GetHandleSize ((*opendir_hand)->path) == expected_size)
- SetWTitle ((WindowPtr) wp, s);
- }
- HSetState ((Handle) opendir_hand, state);
- }
- }
- DisposHandle (old_path);
- DisposHandle (new_path);
- }
-
- void
- updatemove (WindowPeek wp, Str255 sp, long dirid, short vrefnum)
- {
- ControlHandle c;
- Str255 s;
-
- mystr255copy (s, sp);
- if (s[s[0]] == ':')
- --s[0];
-
- c = addtolist (wp, s, dirid, vrefnum);
- setoneicon (c);
- ShowControl (c);
- straightenwindow ((WindowPtr) wp);
- }
-
- void
- removefromlist (WindowPeek wp, Str255 s, long dirid, short vrefnum)
- {
- ControlHandle c, *cp;
- short i, n;
-
- cp = **(*(opendirinfo **) wp->refCon)->items;
- for (i = 0; i < (*(opendirinfo **) wp->refCon)->numitems
- && RelString ((*cp[i])->contrlTitle, s, false, false); i++)
- ;
- if (i < (*(opendirinfo **) wp->refCon)->numitems)
- {
- c = cp[i];
- n = --(*(opendirinfo **) wp->refCon)->numitems;
- memmove(cp + i, cp + i + 1, (n - i) * sizeof(cp[0]) );
-
- /* NOTE: I (ctm) have no idea why we need FALSE here. If we use True, bad things will happen
- when we rename folders and then open them up. I'm very suspicions of the entire way the path
- field of an Icon is manipulated, but I don't have time to overhaul this aspect of Loser
- now. */
-
- Dispose_Icon (c, FALSE);
- }
- }
-
- void
- initopendirs (FILE * f)
- {
- CInfoPBRec cpb;
- CWindowPeek wp;
- short c;
- OSErr e;
- char **path;
- Rect r;
- short volume;
-
- while ((c = getc (f)) && (c != EOF))
- {
- ungetc (c, f);
- e = getonefileinfo (f, &cpb, &path, &volume);
- fscanf (f, "%d %d %d %d\n", &r.left, &r.top, &r.right, &r.bottom);
- if (!e && (cpb.hFileInfo.ioFlAttrib & DIRBIT))
- {
- wp = (CWindowPeek) createdirwindow (&cpb, &r, path, volume);
- }
- for (wp = (CWindowPeek) WindowList; wp != 0; wp = wp->nextWindow)
- {
- if (browser_window_p ((WindowPtr) wp))
- {
- setwindowicons (wp);
- ShowWindow ((WindowPtr) wp);
- flush_screen_writes ();
- }
- }
- }
- }
-