home *** CD-ROM | disk | FTP | other *** search
- /*
- * Macintosh Tar
- *
- * The routines in this file deal with the dialogs presented to the user.
- *
- * Written by Craig Ruff.
- *
- * Note that the dialog dealing with directory selection is in dir.c.
- */
-
- #include "tar.h"
- #include <Resources.h>
- #include <SegLoad.h>
-
- /*
- * Dialog definitions
- */
- #define aboutID 128 /* The "About ..." dialog */
- #define okItem 1
-
- #define blockID 129 /* The block size dialog */
- #define sizeItem 3
-
- #define typeID 131 /* Creator/Type dialog */
- #define creatorItem 3
- #define typeItem 4
-
- /*
- * Alert Definitions
- */
- #define badBlockID 129 /* Block size incorrect alert */
- #define osErrID 130 /* Generic OS Error alert */
- #define pgmErrID 131 /* Program logic error alert */
- #define hfsID 132 /* Must run under HFS alert */
- #define askipID 133 /* Skipping archive file note */
- #define stkErrID 134 /* Stack error alert */
- #define dfID 135 /* Disk full alert */
-
- /*
- * AboutFilter - manage the "About ..." dialog
- *
- * Returns when the mouse or a key is pressed anywhere.
- */
- pascal Boolean
- AboutFilter(theDialog, theEvent, itemHit)
- DialogPtr theDialog;
- EventRecord *theEvent;
- short *itemHit;
- {
- #pragma unused(theDialog)
-
- switch (theEvent->what) {
- case keyDown:
- case mouseDown:
- *itemHit = 1;
- return(true);
- break;
-
- default:
- return(false);
- break;
- }
- }
-
- /*
- * DoAboutBox - put the "About ..." dialog on the screen
- */
- DoAboutBox() {
- short itemHit, itemType;
- WindowPtr myWindow;
- GrafPtr thePort;
- PenState pn;
- Rect okBox;
- Handle okHdl;
-
- GetPort(&thePort);
- myWindow = GetNewDialog(aboutID, nil, (WindowPtr) -1);
- GetDItem(myWindow, okItem, &itemType, &okHdl, &okBox);
- SetPort(myWindow);
- InsetRect(&okBox, -4, -4);
- GetPenState(&pn);
- PenSize(3, 3);
- FrameRoundRect(&okBox, 16, 16);
- SetPenState(&pn);
- do {
- ModalDialog(AboutFilter, &itemHit);
- } while (itemHit != 1);
-
- DisposDialog(myWindow);
- SetPort(thePort);
- }
-
- /*
- * ValidBlockSize - checks the user entered blocksize for validity.
- *
- * Returns true if ok, false if bad.
- */
- Boolean
- ValidBlockSize(theDialog)
- DialogPtr theDialog;
- {
- long n;
- short type;
- Handle hdl;
- Rect box;
- char text[256];
-
- GetDItem(theDialog, sizeItem, &type, &hdl, &box);
- GetIText(hdl, text);
- StringToNum(text, &n);
-
- /*
- * These limits are somewhat arbitrary.
- */
- if ((n < 1) || (n > 128)) {
- NoteAlert(badBlockID, nil);
- SelIText(theDialog, sizeItem, 0, 32767);
- return(false);
- }
-
- blocking = (int) n;
- blockSize = blocking * RECORDSIZE;
- return(true);
- }
-
- Rect okBox; /* ok Box location (gotten once for speed) */
- ControlHandle okHdl; /* ok Box handle */
-
- /*
- * BlockFilter - manage user events during the block size dialog
- *
- * Allows numeric entry and editing, validates size.
- * Returns true if the dialog should exit, false to continue.
- */
- pascal Boolean
- BlockFilter(theDialog, theEvent, itemHit)
- DialogPtr theDialog;
- EventRecord *theEvent;
- short *itemHit;
- {
- long t;
- Point lpt;
- GrafPtr savedPort;
-
- switch (theEvent->what) {
- case keyDown:
- switch ((char) (theEvent->message & charCodeMask)) {
- case RETURN:
- case ENTER:
- goto validate;
- break;
-
- case '0': case '1': case '2': case '3': case '4':
- case '5': case '6': case '7': case '8': case '9':
- case TAB: case BS:
- break;
-
- default:
- SysBeep(5);
- theEvent->what = nullEvent;
- break;
- }
- break;
-
- case mouseDown:
- lpt = theEvent->where;
- GetPort(&savedPort);
- SetPort((GrafPtr) theDialog);
- GlobalToLocal(&lpt);
- SetPort(savedPort);
- if (PtInRect(lpt, &okBox)) {
- validate: if (ValidBlockSize(theDialog)) {
- *itemHit = ok;
- HiliteControl(okHdl, 1);
- Delay(8L, &t);
- HiliteControl(okHdl, 0);
- return(true);
- } else
- theEvent->what = nullEvent;
- }
- break;
- }
-
- return(false);
- }
-
- /*
- * CreatorTypeFilter - manage user events during the Creator/Type dialog
- *
- */
- pascal Boolean
- CreatorTypeFilter(theDialog, theEvent, itemHit)
- DialogPtr theDialog;
- EventRecord *theEvent;
- short *itemHit;
- {
- short type;
- Handle hdl;
- Rect box;
- char text[256];
- int n;
- long t;
- Point lpt;
- GrafPtr savedPort;
-
- switch (theEvent->what) {
- case keyDown:
- switch ((char) (theEvent->message & charCodeMask)) {
- case RETURN:
- case ENTER:
- goto done;
- break;
-
- default:
- break;
- }
- break;
-
- case mouseDown:
- lpt = theEvent->where;
- GetPort(&savedPort);
- SetPort((GrafPtr) theDialog);
- GlobalToLocal(&lpt);
- SetPort(savedPort);
- if (PtInRect(lpt, &okBox)) {
- done:
- GetDItem(theDialog, creatorItem, &type, &hdl, &box);
- GetIText(hdl, text);
- n = (unsigned char) text[0];
- if (n > 4)
- n = 4;
-
- strncpy(fdCreator, &text[1], n);
- GetDItem(theDialog, typeItem, &type, &hdl, &box);
- GetIText(hdl, text);
- n = (unsigned char) text[0];
- if (n > 4)
- n = 4;
-
- strncpy(fdType, &text[1], n);
- *itemHit = ok;
- HiliteControl(okHdl, 1);
- Delay(8L, &t);
- HiliteControl(okHdl, 0);
- return(true);
- }
- break;
- }
-
- return(false);
- }
-
- /*
- * DoBlockSize - put the block size dialog on the screen
- *
- * Puts the current block size into the edit field.
- */
- DoBlockSize() {
- short itemHit;
- DialogPtr theDialog;
- Handle hdl;
- short type;
- Rect box;
- char text[256];
- PenState pn;
- GrafPtr thePort;
-
- GetPort(&thePort);
- theDialog = GetNewDialog(blockID, nil, (WindowPtr) -1);
- GetDItem(theDialog, sizeItem, &type, &hdl, &box);
- NumToString((long) blocking, text);
- SetIText(hdl, text);
- SelIText(theDialog, sizeItem, 0, 32767);
- GetDItem(theDialog, ok, &type, (Handle *) &okHdl, &okBox);
- SetPort(theDialog);
- InsetRect(&okBox, -4, -4);
- GetPenState(&pn);
- PenSize(3, 3);
- FrameRoundRect(&okBox, 16, 16);
- SetPenState(&pn);
- do {
- ModalDialog(BlockFilter, &itemHit);
- } while ((itemHit != ok) && (itemHit != cancel));
-
- DisposDialog(theDialog);
- SetPort(thePort);
- }
-
- /*
- * DoCreatorType - put the set Creator/Type dialog on the screen
- *
- * Puts the current Creator and Type into the edit field.
- */
- DoCreatorType() {
- short itemHit;
- DialogPtr theDialog;
- Handle hdl;
- short type;
- Rect box;
- char text[256];
- PenState pn;
- GrafPtr thePort;
-
- GetPort(&thePort);
- theDialog = GetNewDialog(typeID, nil, (WindowPtr) -1);
- GetDItem(theDialog, creatorItem, &type, &hdl, &box);
- text[0] = 4;
- strncpy(&text[1], fdCreator, 4);
- SetIText(hdl, text);
- GetDItem(theDialog, typeItem, &type, &hdl, &box);
- text[0] = 4;
- strncpy(&text[1], fdType, 4);
- SetIText(hdl, text);
- SelIText(theDialog, creatorItem, 0, 32767);
- GetDItem(theDialog, ok, &type, (Handle *) &okHdl, &okBox);
- SetPort(theDialog);
- InsetRect(&okBox, -4, -4);
- GetPenState(&pn);
- PenSize(3, 3);
- FrameRoundRect(&okBox, 16, 16);
- SetPenState(&pn);
- do {
- ModalDialog(CreatorTypeFilter, &itemHit);
- } while ((itemHit != ok) && (itemHit != cancel));
-
- DisposDialog(theDialog);
- SetPort(thePort);
- }
-
- /*
- * OSAlert - put a generic OS Error Alert on the screen
- *
- * Used for errors not handled in another way (yet).
- */
- OSAlert(p0, p1, p2, err)
- char *p0, *p1, *p2;
- OSErr err;
- {
- char buf[256];
-
- /*
- * Manage the contingency of being called for resources missing!
- */
- if (GetResource('ALRT', osErrID) == nil) {
- GrafPtr wmPort;
- long t;
- Rect r;
-
- GetWMgrPort(&wmPort);
- SetPort(wmPort);
- SetRect(&r, 140, 150, 360, 180);
- EraseRect(&r);
- MoveTo(150,170);
- DrawString("\pPANIC! Resources Missing!");
- Delay(600L, &t);
- ExitToShell();
- }
-
- NumToString((long) err, buf);
- ParamText(p0, p1, p2, buf);
- StopAlert(osErrID, nil);
- }
-
- /*
- * PgmAlert - put a program logic alert on the screen
- */
- PgmAlert(p0, p1, p2)
- char *p0, *p1, *p2;
- {
- ParamText(p0, p1, p2, nil);
- StopAlert(pgmErrID, nil);
- }
-
- /*
- * HFSAlert - put a "HFS only" alert on the screen
- */
- HFSAlert() {
- StopAlert(hfsID, nil);
- }
-
- /*
- * DFAlert - Oops, disk is full
- */
- DFAlert() {
- StopAlert(dfID, nil);
- }
-
- /*
- * ArSkipAlert - put a "skipping archive file" note on the screen
- */
- ArSkipAlert() {
- NoteAlert(askipID, nil);
- }
-
- /*
- * StkErrAlert - put a stack corrupted alert on the screen
- */
- StkErrAlert() {
- StopAlert(stkErrID, nil);
- ExitToShell();
- }
-