home *** CD-ROM | disk | FTP | other *** search
- #include "go.h"
- #include "display.h"
- #include "xfer.h"
- #include <unix.h>
- #include <assert.h>
- #include <string.h>
-
- #include "misc.proto.h"
- #include "update.proto.h"
- #include "inithotband.proto.h"
- #include "initicons.proto.h"
- #include "mouse.proto.h"
-
- #include "windlist.h"
-
- /* todo: move to .h file */
- #define HELPSCROLLBAR 3
- #define HELPPICTITEM 2
- #define HELPDIALOGID 204
- #define HELPPICT 1000
-
- pascal void
- helpscroll (ControlHandle c, short part)
- {
- short v, v2, pagesize;
- short type;
- Rect r;
- Handle h;
- RgnHandle rgn, savergn;
-
- v = GetCtlValue (c);
- pagesize = (*c)->contrlRect.bottom - (*c)->contrlRect.top - 3;
- switch (part)
- {
- case inUpButton:
- SetCtlValue (c, v - SCROLLSPEED);
- break;
- case inDownButton:
- SetCtlValue (c, v + SCROLLSPEED);
- break;
- case inPageDown:
- SetCtlValue (c, v + pagesize);
- break;
- case inPageUp:
- SetCtlValue (c, v - pagesize);
- break;
- default:
- break;
- }
- v2 = GetCtlValue (c);
- GetDItem ((*c)->contrlOwner, HELPPICTITEM, &type, &h, &r);
- rgn = NewRgn ();
- ScrollRect (&r, 0, v - v2, rgn);
- #if 0
- InvalRgn (rgn);
- #else
- savergn = (*c)->contrlOwner->clipRgn;
- (*c)->contrlOwner->clipRgn = rgn;
- drawhelp ((*c)->contrlOwner, HELPPICTITEM);
- (*c)->contrlOwner->clipRgn = savergn;
- #endif
- DisposeRgn (rgn);
- }
-
- pascal void
- drawhelp (DialogPtr dp, short item)
- {
- PicHandle ph;
- Rect r, r2;
- ControlHandle c;
- short offset, type;
- Handle h;
-
- ph = (PicHandle) GetResource ('PICT', HELPPICT);
- GetDItem (dp, HELPSCROLLBAR, &type, (Handle *) & c, &r);
- offset = GetCtlValue (c);
- GetDItem (dp, item, &type, &h, &r);
- InsetRect (&r, -1, -1);
- FrameRect (&r);
- InsetRect (&r, 1, 1);
- ClipRect (&r);
- SetRect (&r2, r.left, r.top - offset,
- r.left + (*ph)->picFrame.right - (*ph)->picFrame.left,
- r.top - offset + (*ph)->picFrame.bottom - (*ph)->picFrame.top);
- CopyBits (&((GrafPtr) (*c)->contrlRfCon)->portBits, &(*c)->contrlOwner->portBits,
- &(*ph)->picFrame, &r2, patCopy, 0);
- ClipRect (&dp->portRect);
- }
-
- pascal char
- helpfilter (DialogPtr dp, EventRecord * ev, short *item)
- {
- ControlHandle c;
- short part;
- Point pt;
- GrafPtr saveport;
-
- if (ev->what == keyDown && (((ev->message & charCodeMask) == '\n') ||
- ((ev->message & charCodeMask) == 13)))
- {
- *item = 1;
- return true;
- }
- else if (ev->what == mouseDown)
- {
- GetPort (&saveport);
- SetPort (dp);
- pt = ev->where;
- GlobalToLocal (&pt);
- part = FindControl (pt, dp, &c);
- switch (part)
- {
- case inThumb:
- TrackControl (c, pt, 0);
- drawhelp ((*c)->contrlOwner, HELPPICTITEM);
- break;
- case inUpButton:
- case inDownButton:
- case inPageUp:
- case inPageDown:
- TrackControl (c, pt, helpscroll);
- break;
- default:
- break;
- }
- SetPort (saveport);
- }
- return false;
- }
-
- void
- help (void)
- {
- short item;
- PicHandle ph;
- Rect r;
- ControlHandle c;
- short type;
- Handle h;
- DialogPtr dp;
- GrafPtr gp;
- GrafPtr saveport;
-
- dp = GetNewDialog (HELPDIALOGID, 0, 0);
- /* TODO: adjust the window size based upon the screen size,
- outline the done button
- */
- GetDItem (dp, HELPSCROLLBAR, &type, (Handle *) & c, &r);
- ph = (PicHandle) GetResource ('PICT', HELPPICT);
- SetCtlMax (c, (*ph)->picFrame.bottom - (*ph)->picFrame.top - r.bottom + r.top);
-
- GetPort (&saveport);
- gp = (GrafPtr) NewPtr (sizeof (GrafPort));
- OpenPort (gp);
- gp->portBits.rowBytes = ((*ph)->picFrame.right - (*ph)->picFrame.left + 15) / 16 * 2;
- gp->portBits.baseAddr = NewPtr (((*ph)->picFrame.bottom - (*ph)->picFrame.top) *
- gp->portBits.rowBytes);
- gp->portBits.bounds = (*ph)->picFrame;
- (*c)->contrlRfCon = (long) gp;
- SetPort (gp);
- ClipRect (&gp->portBits.bounds);
- RectRgn (gp->visRgn, &gp->portBits.bounds);
- EraseRect (&gp->portBits.bounds);
- DrawPicture (ph, &gp->portBits.bounds);
- SetPort (saveport);
-
- GetDItem (dp, HELPPICTITEM, &type, &h, &r);
- SetDItem (dp, HELPPICTITEM, type, (Handle) drawhelp, &r);
- ShowWindow (dp);
- BringToFront (dp);
- ModalDialog ((ProcPtr) helpfilter, &item);
- DisposePtr (gp->portBits.baseAddr);
- ClosePort (gp);
- DisposPtr ((Ptr) gp);
- DisposDialog (dp);
- }
-
- void
- screensaver (void)
- {
- }
-
- void
- setband (short whichband)
- {
- short i, j, type;
- bandinfo *p;
- ControlHandle c;
- Rect r;
-
- p = &bands[g_currentband];
- for (i = p->bandpos; i < p->numitems; i++)
- HideControl ((**p->items)[i]);
- GetDItem (g_hotband, g_currentband + 1, &type, (Handle *) & c, &r);
- HiliteControl (c, 0);
-
- g_currentband = whichband;
- p = &bands[g_currentband];
- for (i = p->bandpos, j = 0; i < p->numitems && j < g_numdispinhotband; i++, j++)
- {
- MoveControl ((**p->items)[i], FIRSTICONX + ICONWIDTHUSED * j, 0);
- ShowControl ((**p->items)[i]);
- }
- GetDItem (g_hotband, g_currentband + 1, &type, (Handle *) & c, &r);
- HiliteControl (c, 255);
- checkhotbandcontrol ();
- }
-
- enum { ODD_COL_OFFSET = 20, TOP_PADDING = 5 };
-
- void
- straightenwindow (WindowPtr wp)
- {
- opendirinfo **infoh;
- short i, h, v, row, col, itemsperrow, height, numrows, ctlheight, top;
- short heightused, widthused;
- ControlHandle c;
- GrafPtr saveport;
-
- GetPort (&saveport);
- SetPort (wp);
- infoh = (opendirinfo **) ((WindowPeek) wp)->refCon;
-
- switch ((*infoh)->view)
- {
- case ICONVIEW:
- widthused = ICONWIDTHUSED;
- heightused = ICONHEIGHTUSED;
- break;
- case ICSVIEW:
- widthused = ICSWIDTHUSED;
- heightused = ICSHEIGHTUSED;
- break;
- case LISTVIEW:
- widthused = LISTWIDTHUSED;
- heightused = LISTHEIGHTUSED;
- break;
- }
- itemsperrow = (wp->portRect.right - wp->portRect.left) / widthused;
-
- /* NOTE: there are currently problems with list view when more than one column
- is used, so I have just made it below so that we never get multi-column list
- view listings. ctm 95-11-05 */
-
- if (itemsperrow < 1 || (*infoh)->view == LISTVIEW)
- itemsperrow = 1;
- numrows = ((*infoh)->numitems - 1) / itemsperrow + 1;
-
- c = (*infoh)->sbar;
- height = wp->portRect.bottom - wp->portRect.top;
- SizeControl (c, SCROLLBARWIDTH, height - SCROLLBARWIDTH + 2);
- top = GetCtlValue (c);
- ctlheight = numrows * heightused + ODD_COL_OFFSET - height + TOP_PADDING;
- if (ctlheight < 0)
- ctlheight = 0;
- SetCtlMax (c, ctlheight);
- if (top > ctlheight)
- top = ctlheight;
- SetCtlValue (c, top);
- SetOrigin (0, top);
- MoveControl (c, wp->portRect.right - SCROLLBARWIDTH + 1, wp->portRect.top);
- drawpartialgrowicon (wp, false);
- for (i = 0; i < (*infoh)->numitems; i++)
- {
- row = i / itemsperrow;
- col = i % itemsperrow;
- v = row * heightused + TOP_PADDING;
- #if 1
- if ((col & 1) && (*infoh)->view == ICONVIEW)
- v += ODD_COL_OFFSET;
-
- #endif
- h = col * widthused;
- MoveControl ((**(*infoh)->items)[i], h, v);
- }
- if (GetCtlMax (c) <= 0)
- HiliteControl (c, 255);
- else
- HiliteControl (c, 0);
- if (FrontWindow () == wp)
- ShowControl (c);
- SetPort (saveport);
- }
-
- /* TODO: move to .h file */
- #define GETINFOID 205
- #define GET_VOLUME_INFO_ID 206
- typedef enum
- {
- GETINFO_OK_ITEM = 1,
- GETINFO_CANCEL_ITEM,
- GETINFO_FILELABEL_ITEM,
- GETINFO_CREATORLABEL_ITEM,
- GETINFO_TYPELABEL_ITEM,
- GETINFO_FILE_ITEM,
- GETINFO_CREATOR_ITEM,
- GETINFO_TYPE_ITEM
- }
- getinfo_items_t;
-
-
- static void
- multiply_and_convert_to_string (Str255 str, long blk_size, unsigned short n_blocks)
- {
- long k, bytes_remaining, m, k_remaining;
-
- blk_size /= 512; /* always guaranteed to be in 512 multiples, right? */
- k = n_blocks * blk_size / 2;
- bytes_remaining = (n_blocks * blk_size) % 2 * 512;
- m = k / 1024;
- k_remaining = k % 1024;
-
- #if 1
- if (m >= 2)
- {
- float m_float;
-
- m_float = ((float) k * 1024 + bytes_remaining) / (1024L * 1024);
- str[0] = sprintf ((char *) str+1, "%.02f megabytes", m_float);
- }
- else
- {
- float k_float;
-
- k_float = k + (float) bytes_remaining / 1024;
- str[0] = sprintf ((char *) str+1, "%.02f kilobytes", k_float);
- }
- #else
- str[0] = sprintf ((char *) str+1, "%ld MB, %ld KB, %ld bytes", m, k_remaining, bytes_remaining);
- #endif
- }
-
- static void
- get_volume_info (ControlHandle c)
- {
- DialogPtr dp;
- short unused;
- HParamBlockRec hpb;
- Str255 name;
- OSErr err;
-
- hpb.ioParam.ioVRefNum = ICON_VREF (c);
- hpb.ioParam.ioNamePtr = name;
- hpb.volumeParam.ioVolIndex = 0;
- err = PBHGetVInfo (&hpb, FALSE);
-
- if (err != noErr)
- ParamText ((StringPtr) "\pERROR", 0, 0, 0);
- else
- {
- Str255 capacity, free;
-
- multiply_and_convert_to_string (capacity, hpb.volumeParam.ioVAlBlkSiz,
- hpb.volumeParam.ioVNmAlBlks);
- multiply_and_convert_to_string (free , hpb.volumeParam.ioVAlBlkSiz,
- hpb.volumeParam.ioVFrBlk);
- ParamText (name, capacity, free, 0);
- }
-
- dp = GetNewDialog (GET_VOLUME_INFO_ID, 0, (WindowPtr) - 1);
- ShowWindow (dp);
- SetPort (dp);
- ModalDialog ((ProcPtr) 0, &unused);
- DisposDialog (dp);
- }
-
- void
- getinfo (void)
- {
- item **ih;
- ControlHandle c;
- CInfoPBRec pb;
- Str255 s;
- DialogPtr dp;
- short type, itemno, valid;
- Rect r;
- Handle h;
- /*
- * TODO: add file size, modification date, etc.
- * outline ok button
- * center window
- * check to see if it's a folder info is gotten about.
- */
-
- c = (**g_selection)[0];
-
- if (is_volume (c))
- {
- get_volume_info (c);
- return;
- }
- ih = (item **) (*c)->contrlData;
- pb.hFileInfo.ioNamePtr = (*c)->contrlTitle;
- pb.hFileInfo.ioVRefNum = (*ih)->vrefnum;
- pb.hFileInfo.ioFDirIndex = 0;
- pb.hFileInfo.ioDirID = (*ih)->ioparid;
- PBGetCatInfo (&pb, false);
-
- dp = GetNewDialog (GETINFOID, 0, (WindowPtr) - 1);
- GetDItem (dp, GETINFO_FILE_ITEM, &type, &h, &r);
- SetIText (h, (*c)->contrlTitle);
- s[0] = 4;
- memcpy ((char *) s + 1, (char *) &pb.hFileInfo.ioFlFndrInfo.fdCreator, 4);
- GetDItem (dp, GETINFO_CREATOR_ITEM, &type, &h, &r);
- SetIText (h, s);
- s[0] = 4;
- memcpy ((char *) s + 1, (char *) &pb.hFileInfo.ioFlFndrInfo.fdType, 4);
- GetDItem (dp, GETINFO_TYPE_ITEM, &type, &h, &r);
- SetIText (h, s);
- SelIText (dp, GETINFO_CREATOR_ITEM, 0, 4);
-
- ShowWindow (dp);
- SetPort (dp);
- do
- {
- ModalDialog ((ProcPtr) 0, &itemno);
- valid = true;
- if (itemno == GETINFO_OK_ITEM)
- {
- GetDItem (dp, GETINFO_CREATOR_ITEM, &type, &h, &r);
- GetIText (h, s);
- if (s[0] != 4)
- valid = false;
- else
- memcpy ((char *) &pb.hFileInfo.ioFlFndrInfo.fdCreator,
- (char *) s + 1, 4);
- GetDItem (dp, GETINFO_TYPE_ITEM, &type, &h, &r);
- GetIText (h, s);
- if (s[0] != 4)
- valid = false;
- else
- memcpy ((char *) &pb.hFileInfo.ioFlFndrInfo.fdType,
- (char *) s + 1, 4);
- if (valid)
- {
- pb.hFileInfo.ioDirID = (*ih)->ioparid;
- PBSetCatInfo (&pb, false);
- setoneicon (c);
- }
- else
- {
- ParamText ((StringPtr) "\pCreators and types are 4 characters long.",
- (StringPtr) "\p", (StringPtr) "\p", (StringPtr) "\p");
- StopAlert (FOUR_PARAM_ALERT, (ProcPtr) 0);
- }
- }
- }
- while (!valid);
- DisposDialog (dp);
- }
-
- void
- savestate (void)
- {
- FILE *f;
- CWindowPeek wp;
- short i, j, res;
-
- unlink (GOBACKUPFILE);
- res = rename (GOSAVEFILE, GOBACKUPFILE);
- #if defined (I_FIGURED_OUT_A_GOOD_WAY_TO_MAKE_SURE_GOSAVEFILE_EXISTED_BEFORE_THE_RENAME)
- if (res)
- {
- ParamText ((StringPtr) "\pThe old state file couldn't be saved",
- (StringPtr) "\p", (StringPtr) "\p", (StringPtr) "\p");
- StopAlert (FOUR_PARAM_ALERT, (ProcPtr) 0);
- return;
- }
- #endif
- f = fopen (GOSAVEFILE, "w");
- if (!f)
- {
- ParamText ((StringPtr) "\pThe browser's state could not be saved.",
- (StringPtr) "\p", (StringPtr) "\p", (StringPtr) "\p");
- StopAlert (FOUR_PARAM_ALERT, (ProcPtr) 0);
- return;
- }
- for (i = 0; i < NUMBANDS; i++)
- {
- if (i != VOLBAND)
- {
- for (j = 0; j < bands[i].numitems; j++)
- fprintf (f, "%s\n",
- *(*(item **) (*(**bands[i].items)[j])->contrlData)->path);
- }
- }
- fprintf (f, "\n");
- #ifdef THINK_C
- for (wp = (CWindowPeek) WindowList; wp != 0; wp = wp->nextWindow)
- {
- #else
- for (wp = (CWindowPeek) LMGetWindowList (); wp != 0; wp = wp->nextWindow)
- {
- #endif
- if (browser_window_p ((WindowPtr) wp))
- {
- fprintf (f, "%s\n", *(*(opendirinfo **) wp->refCon)->path);
- OffsetRect (&wp->port.portRect, -(*wp->port.portPixMap)->bounds.left,
- -(*wp->port.portPixMap)->bounds.top);
- fprintf (f, "%d %d %d %d\n", wp->port.portRect.left,
- wp->port.portRect.top, wp->port.portRect.right,
- wp->port.portRect.bottom);
- }
- }
- res = fclose (f);
- if (res)
- {
- ParamText ((StringPtr) "\pThe browser's state could not be saved.",
- (StringPtr) "\p", (StringPtr) "\p", (StringPtr) "\p");
- StopAlert (FOUR_PARAM_ALERT, (ProcPtr) 0);
- return;
- }
- /* TODO: make save file invisible */
- res = unlink (GOBACKUPFILE);
- if (res)
- {
- ParamText ((StringPtr) "\pThe browser's backup state file could not be removed.",
- (StringPtr) "\p", (StringPtr) "\p", (StringPtr) "\p");
- StopAlert (FOUR_PARAM_ALERT, (ProcPtr) 0);
- return;
- }
- }
-